QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597907#5160. Kebab PizzaAbclWA 0ms3768kbC++142.0kb2024-09-28 19:23:502024-09-28 19:23:52

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 19:23:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-09-28 19:23:50]
  • 提交

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'