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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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).