QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124870#5160. Kebab Pizzajzh#WA 1ms3460kbC++141.9kb2023-07-15 17:06:292023-07-15 17:06:33

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:06:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3460kb
  • [2023-07-15 17:06:29]
  • 提交

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);
    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]++;
        }
    }
    for(int i = 1 ; i <= k ; i ++) {
        if(cnt[i]==0 and d[i]==1 and d[g[i][0]]>2) {
            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();
        }
    }

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

    int tot = 0;
    for(int i = 1 ; i <= k ; i ++) {
        tot += (cnt[i]!=0 or d[i]!=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;
}

詳細信息

Test #1:

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

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: 3400kb

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: 3460kb

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'