QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431643 | #4000. Dynamic Reachability | xlwang | WA | 2ms | 12760kb | C++14 | 4.2kb | 2024-06-05 20:47:15 | 2024-06-05 20:47:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=1e5+10,B=4e2,Maxb=410;
struct node{
int nxt,to,id;
}e[Maxn<<1];
int head[Maxn],cnt;
inline void add(int u,int v,int w){++cnt;e[cnt]=(node){head[u],v,w};head[u]=cnt;}
int dfn[Maxn],low[Maxn],idx,vis[Maxn],col[Maxn],color;
vector<int> stk;
int chs[Maxn],ok[Maxn];
inline void tarjin(int x){
dfn[x]=low[x]=++idx;vis[x]=1;stk.pb(x);
for(register int i=head[x];i;i=e[i].nxt){
if(chs[e[i].id] || !ok[e[i].id]) continue;
int y;y=e[i].to;
// cout<<"*"<<x<<' '<<y<<endl;
if(!dfn[y]){
tarjin(y);
low[x]=min(low[x],low[y]);
}
else if(vis[y]) low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
++color;
int now;
do{
now=stk.back();stk.pop_back();
col[now]=color;vis[now]=0;
}while(now!=x);
}
}
int n,m,q;
int X[Maxn],Y[Maxn];
inline void init(){
n=read();m=read();q=read();
fr(i,1,m) X[i]=read(),Y[i]=read();
fr(i,1,m) add(X[i],Y[i],i);
}
struct Query{
int tp,x,y;
}que[Maxn];
bitset<Maxb> f[Maxn];
vector<int> vc[Maxn];
vector<pii> uped[Maxn];
int val[Maxn],toid[Maxn];
inline void getans(int x,int y){
bitset<Maxb> Ans,now;Ans.reset();queue<int> q;
q.push(x);Ans[x]=1;
while(!q.empty()){
int tmp=q.front();q.pop();
for(auto p:uped[x]){
if(ok[p.second] && !Ans[p.first]) Ans[p.first]=1,q.push(p.first);
}
now=f[toid[x]]&(~Ans);
for(int p=now._Find_first();p^now.size();p=now._Find_next(p)) q.push(p),Ans[p]=1;
}
if(Ans[y]==1) puts("YES");
else puts("NO");
return;
}
inline void solve(int l,int r){
color=idx=0;fr(i,1,n) col[i]=dfn[i]=low[i]=vis[i]=0;
vector<int> ID;
fr(i,l,r) if(que[i].tp==1 && !chs[que[i].x]) chs[que[i].x]=1,ID.pb(que[i].x);
// fr(i,1,m) cout<<i<<' '<<chs[i]<<endl;
fr(i,1,n) if(!dfn[i]) tarjin(i);
// fr(i,1,n) cout<<i<<' '<<col[i]<<endl;
int nod=0;
fr(i,l,r) if(que[i].tp==2){
if(!val[col[que[i].x]]){
val[col[que[i].x]]=++nod;
toid[nod]=col[que[i].x];
}
if(!val[col[que[i].y]]){
val[col[que[i].y]]=++nod;
toid[nod]=col[que[i].y];
}
}
fr(i,1,color) f[i].reset();
fr(i,1,nod) f[toid[i]][i]=1;
fr(i,1,color) vector<int> ().swap(vc[i]);
fr(i,1,m) if(ok[i] && !chs[i] && col[X[i]]!=col[Y[i]]){
vc[col[X[i]]].pb(col[Y[i]]);
}
fr(i,1,color) for(auto y:vc[i]) f[i]|=f[y];
fr(i,1,nod) vector<pii> ().swap(uped[i]);
for(auto i:ID) if(col[X[i]]!=col[Y[i]]) uped[col[X[i]]].pb(mk(col[Y[i]],i));
fr(i,l,r){
if(que[i].tp==1) ok[que[i].x]^=1;
else getans(val[col[que[i].x]],val[col[que[i].y]]);
}
fr(i,l,r) if(que[i].tp==1) chs[que[i].x]=0;
}
inline void work(){
fr(i,1,m) ok[i]=1;
fr(i,1,q){
que[i].tp=read();
if(que[i].tp==1) que[i].x=read();
else que[i].x=read(),que[i].y=read();
}
int l=1,r;
while(l<=r){
r=min(l+B-1,q);
solve(l,r);
l=r+1;
}
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12760kb
input:
5 6 7 1 2 1 3 2 4 3 4 3 5 4 5 2 1 5 2 2 3 1 3 1 4 2 1 4 1 3 2 1 5
output:
result:
wrong answer 1st lines differ - expected: 'YES', found: ''