#include #include #include #include #include #include #include using namespace atcoder; using namespace std; #define ll long long #define P pair #define Pl pair,ll> ostream& operator<<(ostream& os,const P& a){ return os<& a){ for(ll i:a){ os<>& a){ for(vector i:a){ for(int j:i){ os<& a){ for(P i:a){ os<>N; dsu uf(N); vector>to(N); for(int i=0;i>A>>B; uf.merge(A-1,B-1); to.at(A-1).push_back({B-1,i}); if(A!=B){ to.at(B-1).push_back({A-1,i}); } } vector seen(N); //cerr<<"to \n"; vectorans(N,-1); vector> groups=uf.groups(); //cerr< linked:groups){ bool is_cycle=true; ll root=-1,cycle_cnt=0; //vector

degree; /* if(linked.size()==1){ printf("No\n"); cerr<<"0\n"; return 0; } */ for(int point:linked){ ll link_size=to.at(point).size(); //cerr<1){ printf("No\n"); cerr<<"1\n"; return 0; } //サイクルならば、次数が2以上の場所を探す //次数でソートする //cerr<サイクルの場所を切らないといけない //サイクルの場所を検知しないといけない if(is_cycle){ //sort(degree.rbegin(),degree.rend()); //root=degree.at(0).second; //cerr<=2){ next_point=next.first; ans.at(next.second)=root+1; break; } } */ deque

que; que.push_back({linked.at(0),-1}); //cerr<<"que\n"; while(!que.empty()){ P q=que.back(); que.pop_back(); //cerr<<"q:"<dq; dq.push_back(root); while(!dq.empty()){ ll q=dq.back();dq.pop_back(); //cerr<<"q:"<