QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84502 | #4511. Wonderland Chase | yx20220802 | 30 ✓ | 1639ms | 23144kb | C++14 | 2.2kb | 2023-03-06 15:27:43 | 2023-03-06 15:28:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO_ER{
#define LL long long
#define db double
#define ULL unsigned long long
#define In inline
#define f(a,b,i) for(int i=a;i<=b;i++)
#define ff(a,b,i) for(int i=a;i<b;i++)
#define f_(a,b,i) for(int i=a;i>=b;i--)
#define ff_(a,b,i) for(int i=a;i>b;i--)
typedef pair<int,int> Pi;
int inf=0x3f3f3f3f;
int INF=0x7fffffff;
LL infll=0x3f3f3f3f3f3f3f3fll;
LL INFll=0x7fffffffffffffffll;
int FLAG_=0;
char CHAR=0;
template<typename T>void read(T &x){
x=0;
FLAG_=0;
CHAR=getchar();
while(CHAR<'0'||'9'<CHAR){
if(CHAR=='-')FLAG_=1;
CHAR=getchar();
}
while('0'<=CHAR&&CHAR<='9'){
x=(x<<1)+(x<<3)+(CHAR^48);
CHAR=getchar();
}
x=FLAG_?-x:x;
}
template<typename T,typename ...Args>void read(T &x,Args &...args){
read(x);
read(args...);
}
}
using namespace IO_ER;
#define N 200500
int n,m;
vector<int>e[N];
int du[N];
int vis[N];
void ring(){
queue<int>q;
f(1,n,i){
if(du[i]==1){
vis[i]=1;
q.emplace(i);
}
}
while(q.size()){
int u=q.front();q.pop();
for(auto v:e[u]){
if(vis[v])continue;
du[v]--;
if(du[v]==1){
vis[v]=1;
q.emplace(v);
}
}
}
}
int dsa[N];
int dsb[N];
void bfs(int st,int *dis){
f(1,n,i)dis[i]=inf;
queue<int>q;
q.emplace(st);
dis[st]=0;
while(q.size()){
int u=q.front();q.pop();
for(auto v:e[u]){
if(dis[v]!=inf)continue;
dis[v]=dis[u]+1;
q.emplace(v);
}
}
}
int main(){
int T;
int X,Y;
read(T);
f(1,T,kkk){
read(n,m,X,Y);
f(1,n,i)e[i].clear();
f(1,n,i)du[i]=0;
f(1,n,i)vis[i]=0;
int u,v;
f(1,m,i){
read(u,v);
e[u].emplace_back(v);
e[v].emplace_back(u);
du[u]++;
du[v]++;
}
// cout<<1<<endl;
ring();
// f(1,n,i)cout<<vis[i]<<" ";
// cout<<endl;
bfs(X,dsa);
bfs(Y,dsb);
int ans=0;
f(1,n,i){
if(!vis[i]&&dsa[i]<dsb[i]){
printf("Case #%d: SAFE\n",kkk);
goto A;
}
}
f(1,n,i){
if(dsa[i]<dsb[i]){
ans=max(ans,dsb[i]);
}
}
if(ans==inf)printf("Case #%d: SAFE\n",kkk);
else printf("Case #%d: %d\n",kkk,2*ans);
A:;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 8
Accepted
time: 4ms
memory: 9756kb
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: 8 Case #4: 6 Case #5: SAFE Case #6: SAFE Case #7: SAFE Case #8: SAFE Case #9: SAFE Case #10: 8 Case #11: 4 Case #12: 2 Case #13: SAFE Case #14: 2 Case #15: 10 Case #16: 10 Case #17: 6 Case #18: 2 Case #19: 28 Case #20: 28 Case #21: 18 Case #22: 2 Case #23: 58 Case #...
result:
ok 100 lines
Test #2:
score: 22
Accepted
time: 1639ms
memory: 23144kb
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: 8 Case #4: 4 Case #5: 2 Case #6: SAFE Case #7: 2 Case #8: 39998 Case #9: 39998 Case #10: 19192 Case #11: 2 Case #12: 99998 Case #13: 99998 Case #14: 16776 Case #15: 2 Case #16: 199998 Case #17: 199998 Case #18: 141806 Case #19: SAFE Case #20: SAFE Case #21: SAFE ...
result:
ok 100 lines