QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111283#5955. Symmetric Treesyyyyxh0 63ms2376kbC++172.5kb2023-06-06 16:35:012023-06-06 16:35:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-06 16:35:03]
  • 评测
  • 测评结果:0
  • 用时:63ms
  • 内存:2376kb
  • [2023-06-06 16:35:01]
  • 提交

answer

#include <cstdio>
#include <random>
#include <algorithm>
#define fi first
#define se second
using namespace std;
typedef unsigned long long ull;
mt19937_64 rng(2007329);
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=10003;
int n;
ull val[N],ca[26],cb[26];
ull f[N],g[N];
int col[N],sz[N];
int hd[N],ver[N<<1],nxt[N<<1],tot;
void add(int u,int v){
	nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;
}
void dfs(int u,int fa){
	sz[u]=1;
	f[u]=ca[col[u]];
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		dfs(v,u);
		f[u]+=f[v];
		sz[u]+=sz[v];
	}
	f[u]^=cb[col[u]]^val[sz[u]];
}
void calc(int u,int fa){
	ull cur=ca[col[u]]+g[u];
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		cur+=f[v];
	}
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		g[v]=(cur-f[v])^cb[col[u]]^val[n-sz[v]];
		calc(v,u);
	}
}
int eu[N],ev[N];
bool flag,del[N];
pair<ull,int> stk[N];
int tp;
bool vis[N];
void proc(int u,int fa){
	tp=0;vis[u]=1;eu[u]=0;ev[u]=0;
	if(fa) stk[tp++]=make_pair(g[u],fa);
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		stk[tp++]=make_pair(f[v],v);
	}
	sort(stk,stk+tp);
	for(int i=0;i<tp;++i){
		if(i+1==tp||stk[i].fi!=stk[i+1].fi){
			if(eu[u]){
				if(ev[u]){del[u]=1;break;}
				else ev[u]=stk[i].se;
			}
			else eu[u]=stk[i].se;
		}
		else ++i;
	}
	if(!del[u]){
		if(vis[eu[u]]){
			int x=eu[u];
			if(del[x]) del[u]=1;
			else{
				if(u==eu[x]) eu[u]=ev[x];
				if(u==ev[x]) eu[u]=eu[x];
			}
		}
		if(vis[ev[u]]){
			int x=ev[u];
			if(del[x]) del[u]=1;
			else{
				if(u==eu[x]) ev[u]=ev[x];
				if(u==ev[x]) ev[u]=eu[x];
			}
		}
	}
	if(!eu[u]&&!ev[u]&&!del[u]) flag=1;
	int p=0;
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		proc(v,u);
	}
}
void solve(int tid){
	n=read();flag=0;
	for(int i=0;i<26;++i) ca[i]=rng(),cb[i]=rng();
	for(int i=1;i<=n;++i) val[i]=rng();
	char c=getchar();
	for(int i=1;i<=n;++i){
		while(c<'A'||c>'Z') c=getchar();
		col[i]=c-'A';c=getchar();
	}
	for(int i=1;i<n;++i){
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1,0);calc(1,0);proc(1,0);
	if(flag) printf("Case #%d: SYMMETRIC\n",tid);
	else printf("Case #%d: NOT SYMMETRIC\n",tid);
	for(int i=1;i<=n;++i) hd[i]=0,del[i]=vis[i]=0;
	while(tot) ver[tot]=nxt[tot]=0,--tot;
}
int main(){
	int tc=read();
	for(int i=1;i<=tc;++i) solve(i);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 1524kb

input:

100
9
I
P
T
X
E
A
X
E
A
2 8
7 9
6 8
4 6
1 3
3 5
8 9
1 2
4
S
S
S
P
1 2
1 3
2 4
12
Q
Q
Q
Q
Q
Q
Q
Q
Q
Q
Q
Q
1 9
3 5
2 12
9 12
8 10
5 6
5 10
2 11
3 4
2 4
7 8
6
Z
H
H
O
Q
Q
1 4
2 6
4 5
4 6
3 5
6
A
A
A
A
A
A
3 4
2 6
2 3
4 5
1 4
12
K
H
K
K
H
H
H
H
H
H
H
K
3 12
7 8
6 8
7 12
7 9
2 11
2 10
1 12
4 7
2 5
5 12
9...

output:

Case #1: NOT SYMMETRIC
Case #2: NOT SYMMETRIC
Case #3: NOT SYMMETRIC
Case #4: SYMMETRIC
Case #5: SYMMETRIC
Case #6: NOT SYMMETRIC
Case #7: SYMMETRIC
Case #8: SYMMETRIC
Case #9: SYMMETRIC
Case #10: NOT SYMMETRIC
Case #11: SYMMETRIC
Case #12: NOT SYMMETRIC
Case #13: SYMMETRIC
Case #14: NOT SYMMETRIC
C...

result:

wrong answer 1st lines differ - expected: 'Case #1: SYMMETRIC', found: 'Case #1: NOT SYMMETRIC'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 63ms
memory: 2376kb

input:

100
5771
P
P
P
P
P
U
P
U
U
P
P
P
P
P
U
P
P
U
P
U
P
U
P
U
U
U
U
P
P
U
P
U
P
U
P
U
U
U
P
P
P
U
P
P
P
U
P
U
P
U
P
U
P
U
U
P
U
P
U
U
U
U
P
U
P
P
P
P
U
P
U
U
U
U
U
U
U
U
P
U
U
U
P
P
P
U
U
U
U
P
P
P
U
P
P
U
P
U
P
U
U
U
U
U
P
U
P
U
U
U
U
P
U
U
U
P
U
P
U
P
U
U
P
P
P
U
U
P
P
U
P
P
P
U
P
U
P
U
P
P
P
P
P
P
P
P...

output:

Case #1: NOT SYMMETRIC
Case #2: SYMMETRIC
Case #3: NOT SYMMETRIC
Case #4: NOT SYMMETRIC
Case #5: NOT SYMMETRIC
Case #6: NOT SYMMETRIC
Case #7: NOT SYMMETRIC
Case #8: NOT SYMMETRIC
Case #9: NOT SYMMETRIC
Case #10: NOT SYMMETRIC
Case #11: NOT SYMMETRIC
Case #12: NOT SYMMETRIC
Case #13: NOT SYMMETRIC
C...

result:

wrong answer 3rd lines differ - expected: 'Case #3: SYMMETRIC', found: 'Case #3: NOT SYMMETRIC'