QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#382435#4511. Wonderland ChaseKevin53070 1485ms27600kbC++232.2kb2024-04-08 14:13:402024-04-08 14:13:40

Judging History

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

  • [2024-04-08 14:13:40]
  • 评测
  • 测评结果:0
  • 用时:1485ms
  • 内存:27600kb
  • [2024-04-08 14:13:40]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
vector<int> G[100100];
int dfn[100100],tot,low[100100];
bool flag[100100];
int dist1[100100],dist2[100100];
void dfs(int u,int fa=0)
{
	dfn[u]=low[u]=++tot;
	flag[u]=1;
	for(auto v:G[u])
		if(v!=fa)
		{
			if(dfn[v])
				low[u]=min(low[u],dfn[v]);
			else
			{
				dfs(v,u);
				low[u]=min(low[u],low[v]);
				if(low[v]!=dfn[v])
					flag[u]=0;
			}
		}
	if(low[u]!=dfn[u])
		flag[u]=0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int n,m,u,v;
		cin>>n>>m>>v>>u;
		for(int i=1;i<=n;i++)
			G[i].clear();
		for(int i=1;i<=m;i++)
		{
			int a,b;
			cin>>a>>b;
			G[a].pb(b);
			G[b].pb(a);
		}
		tot=0;
		dfs(1);
		queue<int> q;
		memset(dist1,-1,sizeof(dist1));
		memset(dist2,-1,sizeof(dist2));
		q.push(u);
		dist1[u]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(auto y:G[x])
				if(dist1[y]==-1)
				{
					dist1[y]=dist1[x]+1;
					q.push(y);
				}
		}
		q.push(v);
		dist2[v]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(auto y:G[x])
				if(dist2[y]==-1)
				{
					dist2[y]=dist2[x]+1;
					q.push(y);
				}
		}
		bool espace=0;
		for(int i=1;i<=n;i++)
			if(!flag[i]&&dist2[i]<dist1[i])
				espace=1;
		if(espace)
			printf("Case #%d: SAFE\n",tc);
		else
		{
			int ans=0;
			for(int i=1;i<=n;i++)
				if(dist2[i]<=dist1[i])
					ans=max(ans,dist1[i]*2);
			printf("Case #%d: %d\n",tc,ans);
		}
	}
	return 0;
}

詳細信息

Test #1:

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

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: 2
Case #3: SAFE
Case #4: 6
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: SAFE
Case #9: SAFE
Case #10: SAFE
Case #11: SAFE
Case #12: SAFE
Case #13: SAFE
Case #14: 2
Case #15: 10
Case #16: SAFE
Case #17: SAFE
Case #18: SAFE
Case #19: SAFE
Case #20: SAFE
Case #21: SAFE
Case #22...

result:

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

Test #2:

score: 0
Wrong Answer
time: 1485ms
memory: 27600kb

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: SAFE
Case #2: SAFE
Case #3: SAFE
Case #4: 6
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: SAFE
Case #9: SAFE
Case #10: SAFE
Case #11: SAFE
Case #12: SAFE
Case #13: SAFE
Case #14: SAFE
Case #15: SAFE
Case #16: SAFE
Case #17: SAFE
Case #18: SAFE
Case #19: SAFE
Case #20: SAFE
Case #21: SA...

result:

wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: SAFE'