http://mirror.codeforces.com/problemset/problem/28/B
The writer provides a simple solution,but I don't know how to prove the solution is correct. Who can explain it?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
6 | adamant | 157 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
You are given a graph. Each vertex is assigned some unique value. Then you are allowed to exchange assigned values for any two vertices connected with an edge. The question is what assignments you can derive using the above operation any number of times.
Apparently, you can't move a value into other connected component than it has been assigned to before any exchanges. Also it's rather easy to prove that within one connected component you can get any assignment (of course, providing it uses the same set of values as the original one). The idea for the proof is that in a connected graph you may find a vertex that is not an articulation point (i.e. it keeps graph connected when removed), so you may safely put correct value into it and then remove it.
So the solution for original problem would be: for each vertex i check that it is in the same connected component of "allowed swaps graph" as vertex with index value(i).