QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307285#7107. ChaleurMinhhoRE 2ms6760kbC++172.0kb2024-01-18 12:38:212024-01-18 12:38:22

Judging History

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

  • [2024-01-18 12:38:22]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:6760kb
  • [2024-01-18 12:38:21]
  • 提交

answer

#define taskname "F"
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn];
int d[maxn], id[maxn], mark[maxn], in[maxn], n, m;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tst; cin>>tst; while (tst--)
    {
        cin>>n>>m;
        for (int i=1; i<=n; i++) d[i] = 0, id[i] = i, mark[i] = 0, in[i] = 0, adj[i].clear();
        for (int i=1, u, v; i<=m; i++) cin>>u>>v, adj[u].emplace_back(v), adj[v].emplace_back(u), d[u]++, d[v]++;
        sort(id+1, id+n+1, [](int x, int y) {return d[x] >= d[y];});
        int cut = n;
        for (int i=1; i<=n; i++)
            if (d[id[i]] < (i - 1))
            {
                cut = i - 1;
                break;
            }
            else mark[id[i]] = 1;
        mark[id[cut]] = 0;
        int cnt = 0;
        vector<int> split;
        for (int i=cut; i<=n; i++) if (d[id[i]] < cut - 1) break;
        else
        {
            int cur = 1;
            for (int v: adj[id[i]]) cur += mark[v];
            if (cur == cut)
            {
                cnt++;
                if (split.empty())
                {
                    split.emplace_back(id[i]);
                    for (int v: adj[id[i]]) if (mark[v]) split.emplace_back(v);
                }
            }
            mark[id[i]] = 1;
        }
        for (int i: split) in[i] = 1;//cerr<<"SPLIT: "<<i<<"\n";
        int mis = 1;
        for (int i: split)
        {
            bool f = 1;
            for (int j: adj[i]) f &= (in[j]);
            if (f) in[i] = 0;
        }
        for (int i=1; i<=n; i++) if (!in[i])
        {
//            cerr<<"MIS: "<<i<<"\n";
            for (int j: adj[i]) if (in[j])
            {
                if (d[j] > cut) continue;
                bool f = 1;
                for (int k: adj[j]) if (k != i) f &= in[k];
                mis += f;
            }
        }
        if (!mis) mis = cnt;
        cout<<cnt<<" "<<mis<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Runtime Error

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:


result: