QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#66565#5160. Kebab Pizzakaruna#WA 4ms7504kbC++171.6kb2022-12-08 22:38:422022-12-08 22:38:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-08 22:38:43]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:7504kb
  • [2022-12-08 22:38:42]
  • 提交

answer

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

const int N = 101010;
int n, m, deg[N], vis[N], par[N], vz[N], ez[N];
vector<int> g[N];

int Find(int a) {
    return par[a] = (par[a] == a ? a : Find(par[a]));
}
void Union(int a, int b) {
    a = Find(a); b = Find(b);
    ez[a]++;
    if (a != b) {
        vz[a] += vz[b];
        ez[a] += ez[b];
        par[b] = a;
    }
}
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    set<pair<int, int>> st;
    vector<pair<int, int>> e;
    cin >> m >> n;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        if (u != v) {
            if (u > v) swap(u, v);
            st.insert({ u, v });
        }
        e.push_back({ u, v });
    }
    for (auto [x, y] : st) {
        g[x].push_back(y);
        g[y].push_back(x);
        ++deg[x]; ++deg[y];
    }
    vector<int> v;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            v.push_back(i);
        }
    }
    for (int x : v) {
        vis[x] = 1;
        --deg[g[x][0]];
    }
    bool f = true;
    for (int i = 1; i <= n; i++) {
        if (deg[i] > 2) f = false;
    }
    iota(par, par + N, 0);
    fill(vz, vz + N, 1);

    for (auto [x, y] : e) {
        if (!vis[x] && !vis[y]) {
            Union(x, y);
        }
    }
    int cnt = 0, g = 0;
    for (int i = 1; i <= n; i++) if (!vis[i] && Find(i) == i) {
        if (vz[i] >= 3 && ez[i] == vz[i]) {
            g = 1;
        }
        ++cnt;
    }
    if (g == 1 && cnt != 1) f = false;
    
    cout << (f ? "possible" : "impossible");
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 6924kb

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: 4ms
memory: 7040kb

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: 3ms
memory: 6880kb

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: 0
Accepted
time: 3ms
memory: 7080kb

input:

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

output:

possible

result:

ok single line: 'possible'

Test #5:

score: 0
Accepted
time: 2ms
memory: 6948kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 2ms
memory: 7476kb

input:

5 4
1 1
1 4
2 2
2 4
3 4

output:

possible

result:

ok single line: 'possible'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 7504kb

input:

6 4
1 1
1 4
2 2
2 4
3 3
3 4

output:

possible

result:

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