#include<bits/stdc++.h> // 交互题什么的最讨厌了
using namespace std;
using llt=long long;
using llf=long double;
using ull=unsigned long long;
mt19937 rnd(ull(new char)*ull(new char));
const int N=1e5+3;
struct Gph{
int hd[N],to[N<<1],nt[N<<1],wt[N<<1],tot=1;
void Add(int u,int v,int w){wt[++tot]=w,to[tot]=v,nt[tot]=hd[u],hd[u]=tot;}
void ADD(int u,int v,int w){Add(u,v,w),Add(v,u,w);}
#define For_to(i,u,v,g) for(int i=g.hd[u],v=g.to[i];i;i=g.nt[i],v=g.to[i])
}g;
bool p[N]; int ss;
int ca[N],cb[N]; bool wt[N],vis[N];
bool Get(int u){
p[u]=1; bool fg=0;
if(u==ss) return 1;
For_to(i,u,v,g) if(!vis[i>>1]&&g.wt[i]&&!p[v]) fg|=Get(v);
return fg;
}
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cout<<1<<endl;
int n=6,m=10;
cout<<n<<' '<<m<<endl;
for(int i=1;i<n;++i){cb[i]=rnd()%i+1; g.ADD(ca[i]=i+1,cb[i],wt[i]=1); cout<<i+1<<' '<<cb[i]<<endl;}
for(int i=n;i<=m;++i){while(ca[i]==cb[i]) ca[i]=rnd()%n+1,cb[i]=rnd()%n+1; g.ADD(ca[i],cb[i],wt[i]=rnd()%2),cout<<ca[i]<<' '<<cb[i]<<endl;}
while(1){
char opt; cin>>opt;
if(opt=='-'){int i; cin>>i; assert(!vis[i]); vis[i]=1;}
else if(opt=='+'){int i; cin>>i; assert(vis[i]); vis[i]=0;}
else if(opt=='?'){
int s=rnd()%n+1; cin>>ss;
memset(p,0,sizeof(p)),cout<<Get(s)<<endl;
}
else{
assert(opt=='!');
for(int i=1;i<=n;++i){int w; cin>>w; assert(w==wt[i]);}
return 0;
}
}
}
用管道做 OI 交互即可,可以看 this
标签:opt,图论,int,cin,long,vis,using,交互,比较 From: https://www.cnblogs.com/xrlong/p/18456314