QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638967#9453. Graph GeneratortarjenAC ✓178ms13640kbC++201.8kb2024-10-13 17:27:002024-10-13 17:27:01

Judging History

你现在查看的是测评时间为 2024-10-13 17:27:01 的历史记录

  • [2024-10-14 16:54:54]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:171ms
  • 内存:13532kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-13 17:27:01]
  • 评测
  • 测评结果:100
  • 用时:178ms
  • 内存:13640kb
  • [2024-10-13 17:27:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n,m;cin>>n>>m;
    vector<vector<pair<int,int>>> ve(n+1);
    for(int i=1;i<=m;i++){
        int x,y;cin>>x>>y;
        ve[x].emplace_back(y,i);
        ve[y].emplace_back(x,i);
    }
    vector<int> siz(n+1,1);
    vector<int> f(n+1);iota(f.begin(),f.end(),0);
    function<int(int)> getf = [&](int x){
        if(x==f[x])return x;
        else return f[x]=getf(f[x]);
    };
    auto merge= [ &](int x,int y){
        x=getf(x),y=getf(y);
        if(x==y)return;
        f[x]=y;
        siz[y]+=siz[x];
    };
    vector<int>ok(m+1,1);
    vector<int>id(n);iota(id.begin(),id.end(),1);
    sort(id.begin(),id.end(),[&](int x,int y){
        return ve[x].size()>ve[y].size();
    }) ;
    vector<vector<int>>ve2(n+1);
    for(auto x:id){
        for(auto [to,id]:ve[x])if(ok[id]){
            ve2[x].push_back(to);
            ok[id]=0;
        }
    }
    vector<pair<int,vector<int>>> ans;
    for(int i=n-1;i>=0;i--){
        int x=id[i];
        vector<int> v;
        for(auto it:ve2[x])v.emplace_back(getf(it));
        sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
        int sum=0;
        for(auto it:v)sum+=siz[it];
        // cout<<"x="<<x<<" sum="<<sum<<endl;
        if(sum!=ve2[x].size()){
            cout<<"No\n";return;
        }
        ans.emplace_back(x,v);
        for(auto it:v)merge(it,x);
    }
    cout<<"Yes\n";
    for(auto [x,v]:ans){
        cout<<x<<" ";
        cout<<v.size();
        for(auto it:v)cout<<" "<<it;;cout<<"\n";
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--){
        solve();
    }
}
/*
3
3 0

4 4
1 2
2 3
3 4
2 4

5 5
1 2
2 3
3 4
4 5
2 4
*/

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

详细

Test #1:

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

input:

3
3 0
4 4
1 2
2 3
3 4
2 4
5 5
1 2
2 3
3 4
4 5
2 4

output:

Yes
3 0
2 0
1 0
Yes
1 0
4 0
3 1 4
2 2 1 3
No

result:

ok 3 cases passed

Test #2:

score: 0
Accepted
time: 178ms
memory: 13640kb

input:

4176
10 15
1 4
9 1
3 7
8 1
2 1
5 4
5 1
10 1
7 1
10 7
10 3
6 4
3 1
6 1
9 2
7 10
6 7
1 7
1 4
7 2
4 2
5 2
3 1
1 6
2 6
5 1
6 8
5 2
3 1
4 6
2 1
5 1
1 4
6 2
6 1
9 15
5 1
4 2
7 1
1 8
2 3
5 8
1 9
4 3
6 5
9 2
3 1
4 1
7 2
9 7
1 6
6 11
1 2
3 5
3 1
3 2
4 3
1 6
4 2
1 4
5 4
5 1
5 2
6 6
1 6
6 3
1 3
1 5
4 2
2 1
10 ...

output:

Yes
8 0
9 0
6 0
5 0
2 1 9
10 0
7 1 10
4 2 5 6
3 1 7
1 4 2 3 4 8
No
No
No
Yes
6 0
5 0
4 1 5
3 1 4
2 1 3
1 2 2 6
No
No
Yes
2 0
7 0
3 1 7
6 0
5 1 6
4 1 5
1 3 2 3 4
Yes
4 0
9 0
8 0
7 0
5 0
10 0
6 0
3 2 6 10
2 5 3 5 7 8 9
1 2 2 4
Yes
9 0
4 0
6 0
8 0
7 0
5 2 7 8
3 2 5 6
2 1 3
1 2 2 4
Yes
3 0
7 0
6 0
5 0
4...

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed