QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407951 | #4511. Wonderland Chase | dykw | 0 | 1935ms | 13508kb | C++20 | 1.2kb | 2024-05-09 15:19:34 | 2024-05-09 15:19:34 |
Judging History
answer
#include<bits/stdc++.h>
#define I cin
#define O cout
#define N int
#define L long long
#define V vector
#define F pair
#define P first
#define Q second
using namespace std;
void S(){
N n,m,A,B;I>>n>>m>>A>>B;--A,--B;
V<V<N>>e(n);
V<N>d(n);
for(N i=0;i<m;++i){
N u,v;I>>u>>v;--u,--v;
e[u].push_back(v),e[v].push_back(u);
++d[u],++d[v];
}
queue<N>q;
for(N i=0;i<n;++i)if(d[i]==1)q.push(i);
while(q.size()){
N u=q.front();q.pop();
for(N v:e[u]){
if(d[v]){
--d[v],--d[u];
if(!d[v])q.push(v);
}
}
}
V<N>lp;for(N u=0;u<n;++u)if(d[u])lp.push_back(u);
V dA(n,-1),dB(n,-1);
dA[A]=dB[B]=0;
q.push(A);
while(q.size()){
N u=q.front();q.pop();
for(N v:e[u])if(dA[v]==-1){
dA[v]=dA[u]+1;
q.push(v);
}
}
q.push(B);
while(q.size()){
N u=q.front();q.pop();
for(N v:e[u])if(dB[v]==-1){
dB[v]=dB[u]+1;
q.push(v);
}
}
if(dA[B]==-1)return O<<"SAFE\n",void();
for(N u:lp)if(dA[u]!=-1&&dA[u]<dB[u])
return O<<"SAFE\n",void();
N ans=0;
for(N u=0;u<n;++u){
if(dA[u]!=-1&&dA[u]<dB[u])ans=max(ans,dB[u]);
}O<<ans*2<<'\n';
}
signed main(){cin.tie(0)->sync_with_stdio(0);
N T;I>>T;
for(N i=1;i<=T;++i){O<<"Case #"<<i<<": ";S();}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3536kb
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: SAFE Case #4: SAFE Case #5: SAFE Case #6: SAFE Case #7: SAFE Case #8: SAFE Case #9: SAFE Case #10: SAFE Case #11: 4 Case #12: 2 Case #13: SAFE Case #14: 2 Case #15: SAFE Case #16: SAFE Case #17: SAFE Case #18: 2 Case #19: SAFE Case #20: SAFE Case #21: SAFE Case #22:...
result:
wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: SAFE'
Test #2:
score: 0
Wrong Answer
time: 1935ms
memory: 13508kb
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: 4 Case #5: 2 Case #6: SAFE Case #7: 2 Case #8: SAFE Case #9: SAFE Case #10: SAFE Case #11: 2 Case #12: SAFE Case #13: SAFE Case #14: SAFE Case #15: 2 Case #16: SAFE Case #17: SAFE Case #18: SAFE Case #19: SAFE Case #20: SAFE Case #21: SAFE Case #22:...
result:
wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: SAFE'