我使用的并查集维护
void solve(){
int n,m;cin>>n>>m;
DSU dsu(n*2+10);
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
rge(u,v+n);
rge(v,u+n);
}
int ok=0,pos=0;
for(int i=1;i<=n;i++){
if(dsu.find(i)==dsu.find(i+n)){
ok=1;
}
}
if(ok){
cout<<"Alice"<<endl;
for(int i=0;i<n;i++){
cout<<1<<" "<<2<<endl;
int l,r;cin>>l>>r;
}
}else {
cout<<"Bob"<<endl;
vector<int> a, b;
for (int i = 1; i <= n; i++) {
if (dsu.find(i) == dsu.find(1)) {
a.push_back(i);
} else {
b.push_back(i);
}
}
for (int i = 0; i<n; i++) {
int x, y;cin>>x>>y;
vector<int>cnt(4,0);
cnt[x]++;cnt[y]++;
if (a.empty()) {
cout<<b.back()<<" "<<(cnt[2] ? 2 : 3)<<endl;
b.pop_back();
continue;
}
if (b.empty()) {
cout<<a.back()<<" "<<(cnt[1]? 1 : 3)<<endl;
a.pop_back();
continue;
}
if (cnt[2]) {
cout<<b.back()<<" " <<2<<endl;
b.pop_back();
} else {
cout<<a.back()<<" "<<1<<endl;
a.pop_back();
}
}
}
}
数学联邦政治世界观提示您:看后求收藏(同人小说网http://tongren.me),接着再看更方便。