QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#597907 | #5160. Kebab Pizza | Abcl | WA | 0ms | 3768kb | C++14 | 2.0kb | 2024-09-28 19:23:50 | 2024-09-28 19:23:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<':'<<x<<endl;
typedef long long ll;
int main(){
int n,k;
cin>>n>>k;
vector<vector<int>>G(k);
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
a--;b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<bool>cr(k);//非叶子节点 true
for(int i=0;i<k;i++){
set<int>x(G[i].begin(),G[i].end());
cr[i]=x.size() >=1;
//debug(cr[i]);
}
vector<bool>visited(k);
int cycles=0;
int paths=0;
for(int i=0;i<k;i++){
if(visited[i]||!cr[i]) continue;
stack<int>S;
S.push(i);
visited[i]=true;
bool is_cycle=true;
while(!S.empty()){
int cur=S.top();S.pop();
set<int>cur_adj;
for(auto nxt: G[cur]){
if(cr[nxt]&&nxt!=cur){
cur_adj.insert(nxt);
}
}
if(cur_adj.size()>2){
cout<<"impossible"<<endl;
return 0;
}
if(cur_adj.size()<=1){
is_cycle=false;
}
for(auto nxt:cur_adj){
if(!visited[nxt]){
S.push(nxt);
visited[nxt]=true;
}
}
}
if(is_cycle) {
// debug(i);
cycles++;
}
else paths++;
}
if(cycles==1) {
for (int i = 0; i < k; i++) {
for (auto v: G[i]) {
if (!cr[i] && !cr[v]) {
cout << "impossible" << endl;
return 0;
}
}
}
if (paths == 0) {
cout << "possible" << endl;
return 0;
}
cout << "impossible" << endl;
return 0;
}
if(cycles>1){
cout<<"impossible"<<endl;
return 0;
}
cout<<"possible"<<endl;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3768kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'