QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#149084 | #5160. Kebab Pizza | LaStataleBlue# | WA | 5ms | 12900kb | C++23 | 2.1kb | 2023-08-23 23:57:54 | 2023-08-23 23:57:55 |
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])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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 12832kb
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: 12832kb
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: 0ms
memory: 12900kb
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: 5ms
memory: 12836kb
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: 12876kb
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: 12812kb
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: 12832kb
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: 5ms
memory: 12836kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'