Submission #70494339


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define INF (int)(1e9)
#define pii pair<int,int>
#define fir first
#define sec second

inline int read(){
   char ch=getchar(); int f=1;
   while(ch>'9'||ch<'0'){ if(ch=='-') f=-1; ch=getchar();}
   int sum=ch-'0';
   while((ch=getchar())>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch^48);
   return sum*f;
}
inline void chkmax(int &x,int y){x=x<y?y:x;}
inline void chkmin(int &x,int y){x=y<x?y:x;}
int qpow(int a,int b,int p){
	int ret=1;
	while(b){
		if(b&1) ret=ret*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ret;
}
const int N=2e6+9,M=2e5+9;
const int MOD=1e9+7;

int n,m,tot,tag[N];
map<pii,int> mp;
int qt;
struct node{int u,v,id;} q[N];
vector<int> G[N]; 
int fa[N],f[N][30],dep[N];
int find(int u){ return fa[u]==u?u:fa[u]=find(fa[u]); }
void dfs(int u,int fa){
	f[u][0]=fa; dep[u]=dep[fa]+1;
	chkmin(tag[u],tag[fa]);
	for(register int j=1;j<=29;++j) f[u][j]=f[f[u][j-1]][j-1];
	for(auto v:G[u]) dfs(v,u); 
}
int lca(int u,int v){
	if(dep[u]>dep[v]) swap(u,v);
	for(register int j=29;j>=0;--j)
		if(dep[f[v][j]]>=dep[u])
			v=f[v][j];
	if(u==v) return u;
	for(register int j=29;j>=0;--j)
		if(f[u][j]!=f[v][j])
			u=f[u][j],v=f[v][j];
	return f[u][0];
}
signed main(){
	n=read(),m=read();
	tag[0]=INF;
	for(register int i=1;i<=2*n;++i) fa[i]=i,tag[i]=INF;
	tot=n;
	for(register int i=1;i<=m;++i){
		int op=read();
		if(op==1){
			int u=read(),v=read();
            if(u>v) swap(u,v);
			mp[{u,v}]=1;
			u=find(u),v=find(v);
			if(u!=v){
				fa[u]=fa[v]=++tot;
				G[tot].emplace_back(u); G[tot].emplace_back(v);
			}
		} 
		if(op==2){
			int x=read(),y=read(); x=find(x);
			chkmin(tag[x],i); 
		}
		if(op==3){
			int u=read(),v=read();
            if(u>v) swap(u,v);
			if(mp[{u,v}]) q[++qt]={u,v,-1};
			else q[++qt]={u,v,i}; 
		}
	}
	for(register int i=1;i<=tot;++i)
		if(find(i)==i) dfs(i,0);
	for(register int i=1;i<=qt;++i){
		int u=q[i].u,v=q[i].v,id=q[i].id;
		if(id==-1){
            putchar('Y'); putchar('e'); putchar('s');
            putchar('\n');
        }
		else if(find(u)!=find(v)){
            putchar('N'); putchar('o');
            putchar('\n');
        }
		else{
			int tmp=lca(u,v);
			if(tag[tmp]<=id){
                putchar('Y'); putchar('e'); putchar('s');
                putchar('\n');
            }
			else{
                putchar('N'); putchar('o');
                putchar('\n');
            }
		}
	}
}

Submission Info

Submission Time
Task D - Propagating Edges
User XMizukiX
Language C++ 20 (gcc 12.2)
Score 800
Code Size 2482 Byte
Status AC
Exec Time 139 ms
Memory 46532 KiB

Compile Error

Main.cpp: In function ‘void dfs(int, int)’:
Main.cpp:39:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   39 |         for(register int j=1;j<=29;++j) f[u][j]=f[f[u][j-1]][j-1];
      |                          ^
Main.cpp: In function ‘int lca(int, int)’:
Main.cpp:44:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   44 |         for(register int j=29;j>=0;--j)
      |                          ^
Main.cpp:48:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   48 |         for(register int j=29;j>=0;--j)
      |                          ^
Main.cpp: In function ‘int main()’:
Main.cpp:56:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   56 |         for(register int i=1;i<=2*n;++i) fa[i]=i,tag[i]=INF;
      |                          ^
Main.cpp:58:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   58 |         for(register int i=1;i<=m;++i){
      |                          ^
Main.cpp:71:38: warning: unused variable ‘y’ [-Wunused-variable]
   71 |                         int x=read(),y=read(); x=find(x);
      |                                      ^
Main.cpp:81:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   81 |         for(register int i=1;i<=tot;++i)
      |                          ^
Main.cpp:83:26: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   83 |         for(register int i=1;i<=qt;++i){
      |                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 37
Set Name Test Cases
Sample example_0, example_1, example_2
All bigrand_0, bigrand_1, bigrand_2, bigrand_3, bigrand_4, comp_0, comp_1, comp_2, comp_3, example_0, example_1, example_2, rand_0, rand_1, rand_10, rand_11, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9, randcomp_0, randcomp_1, randcomp_2, randcomp_3, randcomp_4, tenc_0, tenc_1, tenc_2, tenc_3, tree_0, tree_1, tree_2, tree_3
Case Name Status Exec Time Memory
bigrand_0 AC 98 ms 37216 KiB
bigrand_1 AC 95 ms 36656 KiB
bigrand_2 AC 95 ms 37276 KiB
bigrand_3 AC 88 ms 36132 KiB
bigrand_4 AC 105 ms 36260 KiB
comp_0 AC 81 ms 29544 KiB
comp_1 AC 76 ms 27292 KiB
comp_2 AC 82 ms 30032 KiB
comp_3 AC 76 ms 27240 KiB
example_0 AC 8 ms 3468 KiB
example_1 AC 8 ms 3472 KiB
example_2 AC 8 ms 3660 KiB
rand_0 AC 8 ms 3480 KiB
rand_1 AC 8 ms 3500 KiB
rand_10 AC 8 ms 3552 KiB
rand_11 AC 8 ms 3532 KiB
rand_2 AC 8 ms 3476 KiB
rand_3 AC 8 ms 3500 KiB
rand_4 AC 8 ms 3580 KiB
rand_5 AC 8 ms 3408 KiB
rand_6 AC 8 ms 3484 KiB
rand_7 AC 8 ms 3484 KiB
rand_8 AC 8 ms 3488 KiB
rand_9 AC 8 ms 3480 KiB
randcomp_0 AC 134 ms 44300 KiB
randcomp_1 AC 139 ms 46532 KiB
randcomp_2 AC 133 ms 44428 KiB
randcomp_3 AC 138 ms 46244 KiB
randcomp_4 AC 133 ms 44204 KiB
tenc_0 AC 77 ms 29188 KiB
tenc_1 AC 76 ms 26876 KiB
tenc_2 AC 76 ms 29280 KiB
tenc_3 AC 77 ms 26744 KiB
tree_0 AC 70 ms 28232 KiB
tree_1 AC 86 ms 29584 KiB
tree_2 AC 72 ms 28112 KiB
tree_3 AC 80 ms 27472 KiB