QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186871 | #5160. Kebab Pizza | Forever_Young# | WA | 3ms | 12724kb | C++14 | 1.2kb | 2023-09-24 12:54:47 | 2023-09-24 12:54:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,k,a[100010][2],inc[100010],cir,seq,one[100010],vis[100010];
set<int> s[100010];
vector<int> edge[100010];
int dfs(int x,int y){
int res=0;
vis[x]=1;
for (int i=0;i<edge[x].size();i++)
if (edge[x][i]!=y){
if (vis[edge[x][i]]) res=1;
else res|=dfs(edge[x][i],x);
}
return res;
}
int main(){
scanf("%d%d",&n,&k);
for (int i=0;i<n;i++){
scanf("%d%d",&a[i][0],&a[i][1]);
s[a[i][0]].insert(a[i][1]);
s[a[i][1]].insert(a[i][0]);
}
//short
for (int i=1;i<=k;i++)
if (s[i].size()==1) one[i]=1;
for (int i=1;i<=k;i++)
if (one[i]&&!s[i].empty()){
int tmp=*s[i].begin();
if (s[tmp].size()==1) seq=1;
s[tmp].erase(i);
}
//long
for (int i=1;i<=k;i++)
if (!one[i]){
s[i].erase(i);
if (s[i].size()==0) seq=1;
else if (s[i].size()>2){
printf("impossible\n");
return 0;
}
else{
for (set<int>::iterator it=s[i].begin();it!=s[i].end();++it)
edge[i].push_back(*it);
}
}
for (int i=1;i<=k;i++)
if (!vis[i]&&!one[i]){
if (dfs(i,0)) cir=1;
else seq=1;
}
if (cir==1&&seq==0) printf("possible\n");
else if (cir==0) printf("possible\n");
else printf("impossible\n");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11660kb
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: 0ms
memory: 11876kb
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: 2ms
memory: 12724kb
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: 2ms
memory: 10876kb
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: 2ms
memory: 12384kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 0ms
memory: 11632kb
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: 2ms
memory: 12272kb
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: 0
Accepted
time: 3ms
memory: 10852kb
input:
4 5 1 2 3 4 4 5 5 3
output:
impossible
result:
ok single line: 'impossible'
Test #9:
score: 0
Accepted
time: 3ms
memory: 11236kb
input:
4 4 1 1 2 3 3 4 4 2
output:
impossible
result:
ok single line: 'impossible'
Test #10:
score: -100
Wrong Answer
time: 3ms
memory: 11028kb
input:
3 4 1 2 2 3 3 1
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'