#include using namespace std; struct union_find_tree { std::vector par, rank; union_find_tree(){} union_find_tree(int size) { par=std::vector(size); rank=std::vector(size); for(int i=0; i>n>>m; union_find_tree t(n); vector boss(n), size(n, 1); for(int i=0; i>a>>b; --a, --b; if (t.same(a, b)) continue; int bossA=boss[t.root(a)]; int bossB=boss[t.root(b)]; t.unite(a, b); int win, lose; if (size[bossA]==size[bossB]) { win=min(bossA, bossB); lose=max(bossA, bossB); } else { win=bossA, lose=bossB; if (size[bossA]