QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#43115#4511. Wonderland Chasexiaoyaowudi0 9252ms112428kbC++141.7kb2022-08-08 08:46:062022-08-08 08:46:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-08 08:46:08]
  • 评测
  • 测评结果:0
  • 用时:9252ms
  • 内存:112428kb
  • [2022-08-08 08:46:06]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
constexpr int N=200010,inf=1e9;
vector<int> es[N];
int d1[N],d2[N];
void bfs(int s,int (&d)[N],int n)
{
	static bool vis[N];
	fill(d+1,d+n+1,inf);
	memset(vis+1,0,sizeof(bool)*n);
	vis[s]=true;d[s]=0;
	static queue<int> qq;
	qq.push(s);
	while(!qq.empty())
	{
		int u=qq.front();qq.pop();
		for(int v:es[u])
		{
			if(!vis[v])
			{
				d[v]=d[u]+1;
				vis[v]=true;
				qq.push(v);
			}
		}
	}
}
bool hc[N],vd[N];int dfn[N],dcnt,low[N];
void dfs(int u,int fa)
{
	vd[u]=true;dfn[u]=low[u]=++dcnt;
	for(int v:es[u])
	{
		if(v==fa)
			continue;
		if(dfn[v])
			low[u]=min(low[u],dfn[v]);
		else
			dfs(v,u),low[u]=min(low[u],low[v]);
	}
	if(low[u]<dfn[u])
		hc[u]=true;
}
int main()
{
	int TC;
	scanf("%d",&TC);
	for(int ti(1),n,m,A,Q;ti<=TC;++ti)
	{
		scanf("%d%d%d%d",&n,&m,&A,&Q);
		for(int i(1),u,v;i<=m;++i)
		{
			scanf("%d%d",&u,&v);
			es[u].push_back(v);es[v].push_back(u);
		}
		memset(hc,0,sizeof(hc));
		memset(vd,0,sizeof(vd));
		memset(dfn,0,sizeof(dfn));
		dcnt=0;
		bfs(A,d1,n);bfs(Q,d2,n);dfs(Q,0);
		if(d2[A]==inf)
		{
			printf("Case #%d: SAFE\n",ti);
			continue;
		}
		bool ok=false;
		// for(int i(1);i<=n;++i)
		// 	printf("%d,%d,%d ",hc[i],d1[i],d2[i]);
		// printf("\n");
		for(int i(1);i<=n;++i)
		if(d1[i]<d2[i] && hc[i])
			ok=true;
		if(ok)
		{
			printf("Case #%d: SAFE\n",ti);
			continue;
		}
		else
		{
			int ans=0;
			for(int i(1);i<=n;++i)
			if(d1[i]<d2[i])
				ans=max<int>(ans,d2[i]*2);
			printf("Case #%d: %d\n",ti,ans);
		}
		for(int i(1);i<=n;++i)
			es[i].clear();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 9100kb

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: 6
Case #4: 6
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: 18
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: SAFE
Case ...

result:

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

Test #2:

score: 0
Wrong Answer
time: 9252ms
memory: 112428kb

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: SAFE
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:...

result:

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