QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658125 | #9484. Colored Complete Graph | NYCU_CartesianTree (CHAO YUAN HUO, YI YANG HUNG)# | WA | 1ms | 3616kb | C++20 | 1.3kb | 2024-10-19 16:12:37 | 2024-10-19 16:12:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
const int mol=998244353;
const int N = 5e4+5;
struct Dsu{
int dsu[N], sz[N];
void init(int n){
for(int i=1;i<=n;i++) dsu[i]=i, sz[i]=1;
}
int find(int g){
if(g==dsu[g]) return g;
return dsu[g]=find(dsu[g]);
}
void un(int g, int h){
g=find(g), h=find(h);
if(g>h) swap(g, h);
dsu[g]=h, sz[h]+=sz[g];
}
}iu1, iu2;
vector<pair<int, int>>e1, e2;
void solve(){
int n;
cin>>n;
iu1.init(n), iu2.init(n);
for(int i=1;i<=n/2;i++){
for(int j=n/2+1;j<=n;j++){
if(iu1.find(j)!=iu1.find(i)&&iu2.find(j)!=iu2.find(i)){
cout<<"? "<<i<<" "<<j<<endl;
char t;
cin>>t;
if(t=='R'){
iu1.un(i, j);
e1.pb({i, j});
}
else{
iu2.un(i, j);
e2.pb({i, j});
}
}
if(e1.size()==n-1||e2.size()==n-1){
break;
}
}
if(e1.size()==n-1||e2.size()==n-1){
break;
}
}
cout<<"!"<<endl;
if(e1.size()!=n-1) e1=e2;
for(auto tt: e1) cout<<tt.F<<" "<<tt.S<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3616kb
input:
3 B R
output:
? 1 2 ? 1 3 ! 1 2
result:
wrong answer guessed graph is incorrect