QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149085 | #5160. Kebab Pizza | LaStataleBlue# | WA | 5ms | 13168kb | C++23 | 2.2kb | 2023-08-24 00:01:40 | 2023-08-24 00:01:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100'005;
set<int> ds[MAXN],grafo[MAXN],tot;
int st,cont;
bool vis[MAXN];
bool dfs(int nodo,int last){
//cout<<"nodo "<<nodo<<" "<<last<<"\n";
vis[nodo]=true;
cont++;
bool res=false;
for(auto i : grafo[nodo]){
if(vis[i]==false){
res=dfs(i,nodo);
}else{
if(i==st && last!=st){
return true;
}
}
}
return res;
}
void solve(int t){
int n,k;
cin>>n>>k;
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
if(a[i]==b[i]){
b[i]=++k;
}
//if(a[i]==b[i])continue;
ds[a[i]].insert(b[i]);
ds[b[i]].insert(a[i]);
}
for(int i=0;i<n;i++){
if(a[i]==b[i]){
tot.insert(a[i]);
continue;
}
if(ds[a[i]].size()>1 && ds[b[i]].size()>1){
grafo[b[i]].insert(a[i]);
grafo[a[i]].insert(b[i]);
}
}
for(int i=1;i<=k;i++){
if(ds[i].size()>1){
tot.insert(i);
}
}
for(int i=1;i<=k;i++){
if(grafo[i].size()>2){
cout<<"impossible\n";
return;
}
}
/*
for(auto i : tot)cout<<i<<" ";
cout<<"\n";
for(int i=1;i<=k;i++){
cout<<i<<" = ";
for(auto j : grafo[i]){
cout<<j<<" ";
}
cout<<"\n";
}
*/
for(int i=1;i<=k;i++){
if(vis[i]==false){
st=i;
cont=0;
bool flag = dfs(i,-1);
//cout<<i<<" "<<cont<<" "<<flag<<"\n";
if(flag && cont==tot.size()){
cout<<"possible\n";
return;
}
if(flag){
cout<<"impossible\n";
return;
}
}
}
cout<<"possible\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve(i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 12996kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
possible
result:
ok single line: 'possible'
Test #2:
score: 0
Accepted
time: 5ms
memory: 13020kb
input:
5 5 1 3 1 5 2 3 2 5 3 4
output:
possible
result:
ok single line: 'possible'
Test #3:
score: 0
Accepted
time: 4ms
memory: 12916kb
input:
6 7 1 2 2 3 3 4 4 5 3 6 6 7
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 4ms
memory: 12924kb
input:
8 4 1 1 1 2 2 1 2 2 3 3 3 4 4 3 4 4
output:
possible
result:
ok single line: 'possible'
Test #5:
score: 0
Accepted
time: 1ms
memory: 12912kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 4ms
memory: 13168kb
input:
5 4 1 1 1 4 2 2 2 4 3 4
output:
possible
result:
ok single line: 'possible'
Test #7:
score: 0
Accepted
time: 1ms
memory: 12880kb
input:
6 4 1 1 1 4 2 2 2 4 3 3 3 4
output:
impossible
result:
ok single line: 'impossible'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 12984kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'