QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201712 | #5160. Kebab Pizza | Rd_rainydays# | WA | 2ms | 8472kb | C++14 | 1.0kb | 2023-10-05 16:22:05 | 2023-10-05 16:22:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define INF 0x3f3f3f3f
static const int M=100003;
vector<int>E[M],TE[M];
int n,k,D[M],d,all;
bool Vis[M],cir;
void Find(int x,int f){
Vis[x]=1;d++;
for(auto y:TE[x]){
if(y!=f){
//cerr<<x<<"->"<<y<<endl;
if(Vis[y])
cir=1;
else Find(y,x);
}
}
}
int main(){
scanf("%d%d",&n,&k);
REP(i,0,n){
int a,b;
scanf("%d%d",&a,&b);
E[a].push_back(b);
E[b].push_back(a);
}
REP(a,1,k+1){
sort(E[a].begin(),E[a].end());
D[a]=unique(E[a].begin(),E[a].end())-E[a].begin();
}
REP(a,1,k+1){
int t=0;
REP(i,0,D[a]){
int b=E[a][i];
if(b==a)continue;
if(D[a]>1 && D[b]>1)
TE[a].push_back(b);
}
if(((int)TE[a].size())>2){
puts("impossible");
return 0;
}
}
REP(a,1,k+1)if(TE[a].size())++all;
REP(a,1,k+1)if(!Vis[a]){
d=0;cir=0;
Find(a,0);
if(cir && d!=all){
puts("impossible");
return 0;
}
}
puts("possible");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8120kb
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: 8280kb
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: 8420kb
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: 8432kb
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: 0ms
memory: 8188kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 1ms
memory: 8116kb
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: 8344kb
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: 2ms
memory: 8472kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'