QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84736 | #4511. Wonderland Chase | Appleblue17 | 0 | 4ms | 6864kb | C++14 | 1.2kb | 2023-03-06 18:06:12 | 2023-03-06 18:07:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,INF=1e9;
int T_,n,m,S,T,ans;
vector <int> G[N];
int in[N];
queue <int> q;
void bfs(int *dis,int st){
for(int i=1;i<=n;i++) dis[i]=INF;
dis[st]=0;
while(q.size()) q.pop();
q.push(st);
while(q.size()){
int u=q.front(); q.pop();
for(int v: G[u]){
if(dis[v]==INF) dis[v]=dis[u]+1,q.push(v);
}
}
}
int f[N],g[N];
bool vis[N];
void dfs(int u){
if(f[u]>=g[u] || vis[u]) return ;
vis[u]=1;
if(in[u]>1) ans=INF;
else ans=max(ans,g[u]);
for(int v: G[u]){
dfs(v);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>T_;
for(int _=1;_<=T_;_++){
ans=0;
cin>>n>>m>>S>>T;
for(int i=1;i<=n;i++) G[i].clear(),in[i]=vis[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);
in[u]++,in[v]++;
}
for(int i=1;i<=n;i++)
if(in[i]==1) q.push(i);
while(q.size()){
int u=q.front(); q.pop();
for(int v: G[u]){
in[v]--;
if(in[v]==1) q.push(v);
}
}
bfs(f,S);
bfs(g,T);
dfs(S);
printf("Case #%d: ",_);
if(ans==INF) printf("SAFE\n");
else printf("%d\n",ans*2);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 6864kb
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: SAFE Case #2: 0 Case #3: SAFE Case #4: 0 Case #5: SAFE Case #6: 0 Case #7: SAFE Case #8: SAFE Case #9: SAFE Case #10: SAFE Case #11: SAFE Case #12: 0 Case #13: 4 Case #14: 0 Case #15: SAFE Case #16: 4 Case #17: SAFE Case #18: 0 Case #19: 0 Case #20: 0 Case #21: 2 Case #22: 0 Case #23: SAFE ...
result:
wrong answer 1st lines differ - expected: 'Case #1: 2', found: 'Case #1: SAFE'
Test #2:
score: 0
Runtime Error
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...