QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227881#5160. Kebab Pizzazx#WA 1ms3432kbC++141.9kb2023-10-28 02:07:012023-10-28 02:07:01

Judging History

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

  • [2023-10-28 02:07:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3432kb
  • [2023-10-28 02:07:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

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.find(i) != x.end() || x.size() > 1;
    }
    
    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;
        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) 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;
    

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3432kb

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'