QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84446 | #4511. Wonderland Chase | fansizhe | 0 | 2750ms | 19880kb | C++23 | 1.5kb | 2023-03-06 15:05:55 | 2023-03-06 15:06:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,A,B;
vector<int> edge[100005];
int deg[100005];
int disA[100005],disB[100005];
int vis[100005];
queue<int> que;
int main(){
int _;scanf("%d",&_);
for(int __=1;__<=_;__++){
scanf("%d%d%d%d",&n,&m,&A,&B);
for(int i=1;i<=n;i++)deg[i]=0,edge[i].clear();
for(int i=1;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
edge[x].push_back(y);
edge[y].push_back(x);
deg[x]++,deg[y]++;
}
memset(vis,0,sizeof(vis));
memset(disA,0x3f,sizeof(disA));
disA[A]=0;vis[A]=1;
que.push(A);
while(!que.empty()){
int x=que.front();que.pop();
for(int y:edge[x])if(!vis[y])disA[y]=disA[x]+1,vis[y]=1,que.push(y);
}
memset(vis,0,sizeof(vis));
memset(disB,0x3f,sizeof(disB));
disB[B]=0;vis[B]=1;
que.push(B);
while(!que.empty()){
int x=que.front();que.pop();
for(int y:edge[x])if(!vis[y])disB[y]=disB[x]+1,vis[y]=1,que.push(y);
}
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)if(deg[i]==1)que.push(i),vis[i]=1;
while(!que.empty()){
int x=que.front();que.pop();
for(int y:edge[x])if(!vis[y]){
deg[y]--;
if(deg[y]==1)que.push(y),vis[y]=1;
}
}
printf("Case #%d: ",__);
if(disA[B]==0x3f3f3f3f){
puts("SAFE");
continue;
}
int ans=0;
for(int i=1;i<=n;i++)if(!vis[i]&&disA[i]<disB[i]){ans=1;break;}
if(!ans){
for(int i=1;i<=n;i++)if(disA[i]<disB[i])ans=max(ans,disB[i]);
printf("%d\n",ans);
}else puts("SAFE");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 7328kb
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: 1 Case #2: SAFE Case #3: 4 Case #4: 3 Case #5: SAFE Case #6: SAFE Case #7: SAFE Case #8: SAFE Case #9: SAFE Case #10: 4 Case #11: 2 Case #12: 1 Case #13: SAFE Case #14: 1 Case #15: 5 Case #16: 5 Case #17: 3 Case #18: 1 Case #19: 14 Case #20: 14 Case #21: 9 Case #22: 1 Case #23: 29 Case #24:...
result:
wrong answer 1st lines differ - expected: 'Case #1: 2', found: 'Case #1: 1'
Test #2:
score: 0
Wrong Answer
time: 2750ms
memory: 19880kb
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: 4 Case #4: 2 Case #5: 1 Case #6: SAFE Case #7: 1 Case #8: 19999 Case #9: 19999 Case #10: 9596 Case #11: 1 Case #12: 49999 Case #13: 49999 Case #14: 8388 Case #15: 1 Case #16: 99999 Case #17: 99999 Case #18: 70903 Case #19: SAFE Case #20: SAFE Case #21: SAFE Case ...
result:
wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: 4'