QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780145#7107. ChaleurrgnerdplayerAC ✓172ms8032kbC++231.6kb2024-11-25 01:59:372024-11-25 01:59:39

Judging History

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

  • [2024-11-25 01:59:39]
  • 评测
  • 测评结果:AC
  • 用时:172ms
  • 内存:8032kb
  • [2024-11-25 01:59:37]
  • 提交

answer

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

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    cin >> t;

    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        vector<vector<int>> adj(n);
        for (int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--, v--;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        vector<int> o(n);
        iota(o.begin(), o.end(), 0);
        sort(o.begin(), o.end(), [&](int i, int j) {
            return adj[i].size() > adj[j].size();
        });

        vector<int> side(n);
        int clique = 0;

        for (auto u : o) {
            int cnt = count_if(adj[u].begin(), adj[u].end(), [&](int v) {
                return side[v];
            });
            if (cnt == clique) {
                clique++;
                side[u] = 1;
            }
        }

        int ans1 = 1, ans2 = 1;

        for (int i = 0; i < n; i++) {
            if (side[i] == 0 && adj[i].size() == clique - 1) {
                ans1++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (side[i] == 1 && adj[i].size() == clique - 1) {
                side[i] = 0;
                clique--;
            }
        }

        for (int i = 0; i < n; i++) {
            if (side[i] == 1 && adj[i].size() == clique) {
                ans2++;
            }
        }

        cout << ans1 << ' ' << ans2 << '\n';        
    };
    
    while (t--) {
        solve();
    }
    
    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

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: 172ms
memory: 8032kb

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