QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549384 | #8686. Zoo Management | ucup-team052 | WA | 1ms | 9760kb | C++23 | 1.6kb | 2024-09-06 15:01:00 | 2024-09-06 15:01:01 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
using namespace std;
const int N=400005;
int n,m,b0[N],b1[N];
vector<int>e[N];
int dfn[N],low[N],st[N],top,idx;
int seq[N],len,bel[N],cnt;
void GG(){puts("impossible"),exit(0);}
void tarjan(int u,int fa){
dfn[u]=low[u]=++idx,st[++top]=u;
for(auto&x:e[u])if(x!=fa){
if(!dfn[x])tarjan(x,u),low[u]=min(low[u],low[x]);
else low[u]=min(low[u],dfn[x]);
}
if(dfn[u]==low[u]){
++cnt;
len=0;
do{
seq[++len]=st[top];
bel[st[top]]=cnt;
}while(st[top--]!=u);
int cnt_e=0;
rep(i,1,len)for(auto&x:e[seq[i]]){
if(x<seq[i]){
++cnt_e;
}
}
if(len==1){
if(b0[seq[1]]!=b1[seq[1]]){
GG();
}
}else{
vector<int>v1,v2;
rep(i,1,len){
v1.pb(b0[seq[i]]);
v2.pb(b1[seq[i]]);
}
if(cnt_e==len){
vector<int>v3(v2);
v3.pop_back();
v3.insert(v3.begin(),v2.back());
vector<int>v4(v2);
v4.erase(v4.begin());
v4.pb(v2[0]);
if(v2!=v1&&v3!=v1&&v4!=v1){
GG();
}
}else{
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
if(v1!=v2)GG();
}
}
}
}
int main(){
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>m;
rep(i,1,n){
cin>>b0[i]>>b1[i];
}
rep(i,1,m){
int u,v;
cin>>u>>v;
e[u].pb(v);
e[v].pb(u);
}
rep(i,1,n)if(!dfn[i])tarjan(i,0);
puts("possible");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7740kb
input:
6 7 1 1 2 2 3 3 1 2 2 3 3 1 1 2 2 3 1 3 3 4 4 5 5 6 4 6
output:
possible
result:
ok single line: 'possible'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 9760kb
input:
5 6 10 10 20 20 30 30 40 50 50 40 1 2 2 3 1 3 3 4 3 5 4 5
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'