QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84548#4511. Wonderland Chasekkio0 3229ms24632kbC++141.4kb2023-03-06 15:49:282023-03-06 15:49:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 15:49:59]
  • 评测
  • 测评结果:0
  • 用时:3229ms
  • 内存:24632kb
  • [2023-03-06 15:49:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10,inf=1e9;
vector<int> G[maxn];
int n,m;
void bfs(int s,int *dis)
{
	for(int i=1;i<=n;i++)dis[i]=-1;
	dis[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int v:G[u])
			if(dis[v]==-1)
			{
				dis[v]=dis[u]+1;
				q.push(v);
			}
	}
	for(int i=1;i<=n;i++)
		if(dis[i]==-1)dis[i]=inf;
}
int Ax[maxn],Bx[maxn],A,B,D[maxn];
queue<int> q;
int deg[maxn];
bool safe[maxn];
int sp[maxn],tot;
void solve(int Caseid)
{
	scanf("%d%d%d%d",&n,&m,&A,&B);
	for(int i=1;i<=n;i++)G[i].clear(),deg[i]=0;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u]++;
		deg[v]++; 
	} 
	for(int i=1;i<=n;i++)if(deg[i]==1)q.push(i);
	for(int i=1;i<=n;i++)safe[i]=1;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		safe[u]=0;
		for(int v:G[u])
		{
			deg[v]--;
			if(deg[v]==1)q.push(v);
		}
	}
	tot=0;
	for(int i=1;i<=n;i++)if(safe[i])sp[++tot]=i;
	bfs(A,D);
	bfs(A,Ax);
	bfs(B,Bx);
	if(D[B]==-1)
		{printf("Case #%d: SAFE\n",Caseid);return;}
	for(int i=1;i<=tot;i++)
		if(Ax[sp[i]]<Bx[sp[i]])
			{printf("Case #%d: SAFE\n",Caseid);return;}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(Bx[i]!=inf)ans=max(ans,Bx[i]*2);
	printf("Case #%d: %d\n",Caseid,ans);
	return;
}
int main()
{
	int T;
	scanf("%d",&T);
	for(int i=1;i<=T;i++)
		solve(i);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 11616kb

input:

100
2 1 1 2
1 2
3 3 1 2
1 3
1 2
2 3
6 6 5 1
1 4
5 6
3 4
3 6
2 3
1 2
6 6 2 4
4 5
1 4
2 3
2 5
1 6
5 6
6 6 2 3
1 3
3 4
2 6
2 5
4 5
1 5
6 5 5 3
2 5
3 4
1 2
3 6
4 6
6 5 1 6
1 4
1 2
5 6
3 5
2 4
30 29 11 5
9 21
25 28
14 20
13 30
21 28
5 18
5 23
8 22
10 30
4 8
7 24
16 26
13 26
12 18
22 23
11 16
3 11
2 17
1 ...

output:

Case #1: 2
Case #2: SAFE
Case #3: 8
Case #4: 6
Case #5: SAFE
Case #6: 2
Case #7: SAFE
Case #8: 20
Case #9: SAFE
Case #10: 8
Case #11: 6
Case #12: 2
Case #13: 2
Case #14: 8
Case #15: 10
Case #16: 10
Case #17: 6
Case #18: 26
Case #19: 28
Case #20: 28
Case #21: 18
Case #22: 56
Case #23: 58
Case #24: 58...

result:

wrong answer 6th lines differ - expected: 'Case #6: SAFE', found: 'Case #6: 2'

Test #2:

score: 0
Wrong Answer
time: 3229ms
memory: 24632kb

input:

100
100000 99999 32832 52005
67463 96972
10280 86580
12146 44520
41541 86634
46936 64223
22701 46291
9093 80967
52512 77386
51062 58931
2092 55026
2096 2384
85102 92986
39914 66949
33370 68952
41576 58836
27668 33997
5843 30705
44415 57721
15188 28706
23340 55082
20335 90872
16029 80328
4656 74633
8...

output:

Case #1: 99990
Case #2: SAFE
Case #3: 8
Case #4: 6
Case #5: 2
Case #6: 2
Case #7: 39996
Case #8: 39998
Case #9: 39998
Case #10: 20806
Case #11: 99996
Case #12: 99998
Case #13: 99998
Case #14: 83222
Case #15: 199996
Case #16: 199998
Case #17: 199998
Case #18: 141806
Case #19: SAFE
Case #20: SAFE
Case...

result:

wrong answer 1st lines differ - expected: 'Case #1: SAFE', found: 'Case #1: 99990'