QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#161881#7107. Chaleurucup-team1198#AC ✓130ms16132kbC++201.9kb2023-09-03 02:31:432023-09-03 02:31:44

Judging History

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

  • [2023-09-03 02:31:44]
  • 评测
  • 测评结果:AC
  • 用时:130ms
  • 内存:16132kb
  • [2023-09-03 02:31:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

const int MAXN = 1e5 + 100;
vector<int> g[MAXN];

int ind[MAXN];

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        g[i].clear();
    }
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [](int i, int j) { return g[i].size() < g[j].size(); });
    for (int i = 0; i < n; ++i) {
        ind[ord[i]] = i;
    }
    int sz = 0;
    for (int i = 0; i < n; ++i) {
        bool f = true;
        for (int u : g[ord[i]]) {
            if (ind[u] < i) {
                f = false;
                break;
            }
        }
        if (!f) break;
        ++sz;
    }
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < sz; ++i) {
        int cur = 0;
        for (int u : g[ord[i]]) {
            if (ind[u] >= sz) {
                ++cur;
            }
        }
        if (cur == n - sz) {
            cnt0++;
        } else if (cur == n - sz - 1) {
            cnt1++;
        }
    }
    if (cnt0 != 0) {
        cout << cnt0 << " ";
    } else {
        cout << cnt1 + 1 << " ";
    }
    cnt0 = 0, cnt1 = 0;
    for (int i = sz; i < n; ++i) {
        int cur = 0;
        for (int u : g[ord[i]]) {
            if (ind[u] < sz) {
                ++cur;
            }
        }
        if (cur == 0) {
            cnt0++;
        } else if (cur == 1) {
            cnt1++;
        }
    }
    if (cnt0 != 0) {
        cout << cnt0 << "\n";
    } else {
        cout << cnt1 + 1 << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }

    return 0;
}

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

詳細信息

Test #1:

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

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: 130ms
memory: 16132kb

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