QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338523#7107. ChaleurLainAC ✓131ms4504kbC++231.3kb2024-02-25 23:59:052024-02-25 23:59:06

Judging History

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

  • [2024-02-25 23:59:06]
  • 评测
  • 测评结果:AC
  • 用时:131ms
  • 内存:4504kb
  • [2024-02-25 23:59:05]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN ((int) 1e5)
using namespace std;
typedef pair<int, int> pii;

int n, m;

int deg[MAXN + 10];
bool flag[MAXN + 10];

void solve() {
    scanf("%d%d", &n, &m);
    if (m == 0) { printf("%d 1\n", n); return; }

    memset(deg, 0, sizeof(int) * (n + 3));
    for (int i = 1; i <= m; i++) {
        int x, y; scanf("%d%d", &x, &y);
        deg[x]++; deg[y]++;
    }

    // 所有节点按度数从大到小排序
    vector<int> vec;
    for (int i = 1; i <= n; i++) vec.push_back(i);
    sort(vec.begin(), vec.end(), [&](int a, int b) {
        return deg[a] > deg[b];
    });

    // 求最大团的大小
    memset(flag, 0, sizeof(bool) * (n + 3));
    int sz = 0;
    for (int x : vec) {
        if (deg[x] >= sz) sz++, flag[x] = true;
        else break;
    }

    // 最大团的方案数
    int ans = 1;
    for (int i = 1; i <= n; i++) if (!flag[i] && deg[i] == sz - 1) ans++;
    printf("%d ", ans);

    // 最大独立集的方案数
    int larger = 0, equal = 1;
    for (int i = 1; i <= n; i++) if (flag[i]) {
        if (deg[i] == sz - 1) larger++;
        else if (deg[i] == sz) equal++;
    }
    printf("%d\n", larger ? larger : equal);
}

int main() {
    int tcase; scanf("%d", &tcase);
    while (tcase--) solve();
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 131ms
memory: 4504kb

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