QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124873#5160. Kebab Pizzajzh#WA 1ms3492kbC++142.0kb2023-07-15 17:16:102023-07-15 17:16:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 17:16:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3492kb
  • [2023-07-15 17:16:10]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k; cin >> n >> k;
    vector<int>d(k+1), cnt(k+1);
    vector<vector<int>>g(k+1);
    vector<int>vis(k+1);
    for(int i = 1 ; i <= n ; i ++) {
        int a, b; cin >> a >> b;
        if(a==b) {
            cnt[a]++;
        }
        else {
            g[a].push_back(b);
            g[b].push_back(a);
            d[a]++, d[b]++;
        }
        vis[a] = vis[b] = true;
    }

    vector<int>del;

    for(int i = 1 ; i <= k ; i ++) {
        if(cnt[i]==0 and d[i]==1 and d[g[i][0]]>2) {
            del.push_back(i);
        }
    }
    auto update = [&](int i) {
        int v = g[i][0];
        d[i]--;
        d[v]--;
        for(int j = 0 ; j < g[v].size() ; j ++) {
            if(g[v][j]==i) {
                g[v].erase(g[v].begin()+j);
                break;
            }
        }
        g[i].pop_back();
        vis[i] = false;
    };
    for(auto &i: del) update(i);

    for(int i = 1 ; i <= k ; i ++) {
        if(d[i]>2) {
            cout << "impossible\n";
            return 0;
        }
    }

    int tot = accumulate(begin(vis), end(vis), 0);

    if(d==vector<int>(k+1, 0)) {
        cout << "possible\n";
        return 0;
    }
    
    for(int i = 1 ; i <= k ; i ++) {
        if(d[i]==2) {
            bool flag = true;
            int now = g[i][0], pre = i, len = 1;
            while(now!=i) {
                ++len;
                if(d[now]==1) {
                    flag = false;
                    break;
                }
                if(g[now][0]==pre) {
                    pre = now;
                    now = g[now][1];
                }
                else {
                    pre = now;
                    now = g[now][0];
                }
            }
            if(flag and len!=tot) {
                cout << "impossible\n";
                return 0;
            }
        }
    }
    cout << "possible\n";


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3492kb

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: 1ms
memory: 3464kb

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: 1ms
memory: 3440kb

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: -100
Wrong Answer
time: 1ms
memory: 3404kb

input:

8 4
1 1
1 2
2 1
2 2
3 3
3 4
4 3
4 4

output:

impossible

result:

wrong answer 1st lines differ - expected: 'possible', found: 'impossible'