QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166658#7107. ChaleurRemakeeAC ✓149ms7612kbC++141.7kb2023-09-06 16:20:252023-09-06 16:20:26

Judging History

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

  • [2023-09-06 16:20:26]
  • 评测
  • 测评结果:AC
  • 用时:149ms
  • 内存:7612kb
  • [2023-09-06 16:20:25]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n, m;
    std::cin >> n >> m;
    
    std::vector<std::vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 0);
    std::sort(p.begin(), p.end(),
        [&](int i, int j) {
            return adj[i].size() > adj[j].size();
        });
    
    std::vector<int> vis(n);
    int cnt = 0;
    for (auto x : p) {
        int res = 0;
        for (auto y : adj[x]) {
            res += vis[y];
        }
        if (cnt == res) {
            vis[x] = 1;
            cnt++;
        }
    }
    for (int x = 0; x < n; x++) {
        for (auto y : adj[x]) {
            assert(vis[x] || vis[y]);
        }
    }
    int ans1 = 1;
    int ans2 = 1;
    for (int i = 0; i < n; i++) {
        if (!vis[i] && adj[i].size() == cnt) {
            assert(false);
        }
        if (!vis[i] && adj[i].size() == cnt - 1) {
            ans1++;
        }
    }
    int num = 0; 
    for (int i = 0; i < n; i++) {
        if (vis[i] && adj[i].size() == cnt - 1) {
            cnt--;
            ++num;
            vis[i] = 0;
        }
    }
    assert(num <= 1);
    for (int i = 0; i < n; i++) {
        if (vis[i] && adj[i].size() == cnt) {
            ans2++;
        }
    }
    std::cout << ans1 << " " << ans2 << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

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

output:

2 1
1 4
1 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 149ms
memory: 7612kb

input:

2231
1 0
5 7
4 1
3 4
3 1
3 5
4 2
3 2
4 5
5 4
2 1
2 5
2 4
2 3
5 10
3 2
2 5
1 4
4 2
4 5
1 2
1 3
3 5
3 4
1 5
5 10
1 3
2 4
1 4
5 2
2 3
1 5
5 4
1 2
3 4
5 3
5 9
2 5
3 5
2 3
2 1
4 3
3 1
4 1
4 5
2 4
5 4
4 2
4 1
4 5
4 3
5 9
4 1
4 5
3 4
2 4
2 1
3 1
2 5
3 5
3 2
5 4
2 5
2 3
2 1
2 4
5 9
5 2
1 3
4 3
1 2
5 4
4 2
5...

output:

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

result:

ok 2231 lines

Extra Test:

score: 0
Extra Test Passed