QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395035#7107. Chaleurucup-team055#AC ✓761ms23720kbC++231.7kb2024-04-21 01:45:262024-04-21 01:45:26

Judging History

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

  • [2024-04-21 01:45:26]
  • 评测
  • 测评结果:AC
  • 用时:761ms
  • 内存:23720kb
  • [2024-04-21 01:45:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < (b); i++)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(auto& a, auto b) { if(a >= b) return 0; a = b; return 1; }


void solve() {
    ll N, M;
    cin >> N >> M;
//    if(M == 0) return {N, 1};
    vector<set<ll>> g(N);
    vector<ll> deg(N);
    vector<pair<ll, ll>> edge(M);
    for(auto& [A, B] : edge) {
        cin >> A >> B;
        A--; B--;
        g[A].insert(B);
        g[B].insert(A);
        deg[A]++;
        deg[B]++;
    }
    vector<ll> cl, ind, pend;
    rep(i, 0, N) pend.push_back(i);
    ranges::sort(pend, {}, [&](ll i) { return deg[i]; });
    while(sz(pend)) {
        const ll i = pend.back();
        pend.pop_back();
        cl.push_back(i);
        vector<ll> A, B;
        for(ll j : pend) (g[i].contains(j) ? A : ind).push_back(j);
        pend = move(A);
    }
    vector<bool> is_cli(N);
    for(ll i : cl) is_cli[i] = 1;
    
    vector<ll> D(N);
    for(auto [i, j] : edge) {
        if(is_cli[i] and is_cli[j]) continue;
        D[i]++;
        D[j]++;
    }
    
    vector<ll> D1, D0;
    rep(i, 0, N) (is_cli[i] ? D1 : D0).push_back(D[i]);
    cout << [&] {
        if(ranges::count(D0, sz(cl))) return ranges::count(D0, sz(cl));
        return 1 + ranges::count(D0, sz(cl) - 1);
    }() << ' ' << [&]{
        if(ranges::count(D1, 0)) return ranges::count(D1, 0);
        return 1 + ranges::count(D1, 1);
    }() << '\n';
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T;
    cin >> T;
    while(T--) solve();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 761ms
memory: 23720kb

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