QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446503#6413. Classical Graph Theory ProblemcqbzlyWA 34ms25408kbC++144.1kb2024-06-17 11:55:352024-06-17 11:55:35

Judging History

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

  • [2024-06-17 11:55:35]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:25408kb
  • [2024-06-17 11:55:35]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define inf 0x3f3f3f3f
using namespace std;
const int N=5e5+5;
int T,n,m,du[N],cnt[N],vs[N],to[N],vs0[N];
struct node{
    int u,v;
}q[N];
struct node0{
    int u,v,i;
};
mt19937 gen(114514);
vector<int>pos[N];
vector<int>v1,v2,v3,st;
vector<node0>vec;
int get(int u,int i=0){
    int j=0;
    while(vs[pos[u][j]]||pos[u][j]==i)j++;
    return pos[u][j];
}
bool check(int u,int i){
    if(du[u]==1)return 0;
    if(du[u]>2)return 1;
    int x=get(u,i);
    if(cnt[q[x].u^q[x].v^u]==2)return 0;
    return 1;
}
void del(int u){
    int x=get(u);
    to[u]=q[x].u^q[x].v^u;
    cnt[to[u]]++;
}
int main(){
    //freopen("data.in","r",stdin);
    // freopen("number.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--){
        cin>>n>>m;
        for(int i=1;i<=n;i++)du[i]=cnt[i]=to[i]=0,pos[i].clear();
        for(int i=1;i<=m;i++){
            int u,v;cin>>u>>v;
            du[u]++,du[v]++,vs[i]=0;
            pos[u].pb(i),pos[v].pb(i);
            q[i]={u,v};
        }
        for(int i=1;i<=m;i++){
            int u=q[i].u,v=q[i].v;
            if(du[u]==1)cnt[v]++,to[u]=v;
            if(du[v]==1)cnt[u]++,to[v]=u;
        }
        for(int i=1;i<=m;i++){
            int u=q[i].u,v=q[i].v;
            if(check(u,i)&&check(v,i)){
                vs[i]=1,du[u]--,du[v]--;
                if(du[u]==1)del(u);
                if(du[v]==1)del(v);
            }
            // else{
            //     cout<<u<<" "<<v<<"\n";
            // }
        }
        for(int i=1;i<=m;i++){
            int u=q[i].u,v=q[i].v;
            if(!vs[i]&&check(u,i)&&check(v,i)){
                assert(0);
            }
        }
        v1.clear(),v2.clear(),v3.clear(),vec.clear(),st.clear();
        for(int i=1;i<=n;i++){
            if(cnt[i]==2){
                v3.pb(i);
            }
            else if(cnt[i]==0&&du[i]>1){
                assert(du[i]==2);
                //cout<<"find:"<<i<<"\n";
                int j=get(i),k=get(i,j),u=q[j].u^q[j].v^i,v=q[k].u^q[k].v^i;
                vec.pb({u,v,i});
            }
            else if(cnt[i]==1){
                assert(du[i]==1);
            }
            else if(cnt[i]==0&&du[i]==1){
                assert(cnt[to[i]]>=1);
            }
        }
        for(int i=1;i<=(v3.size()+1)/2;i++)st.pb(0);
        for(int i=1;i<=v3.size()/2;i++)st.pb(1);
        // for(auto e:vec){
        //     cout<<e.u<<" "<<e.v<<" "<<e.i<<"\n";
        // }
        //for(auto e:v3)cout<<e<<" ";cout<<"\n";
        //cout<<st.size()<<"\n";
        while(1){
            shuffle(st.begin(),st.end(),gen);
            for(int i=0;i<st.size();i++)vs0[v3[i]]=st[i];
            int cnt1=0,cnt2=0;
            for(auto e:vec){
                if(vs0[e.u]!=vs0[e.v])cnt1++;
                else cnt2++;
            }
            if(cnt1>=cnt2){
                for(auto e:v3){
                    if(!vs0[e])v1.pb(e);
                    else v2.pb(e);
                }
                for(int i=1;i<=n;i++){
                    if(cnt[i]==0&&du[i]==1){
                        if(vs0[to[i]])v1.pb(i);
                        else v2.pb(i);
                    }
                }
                for(auto e:vec){
                    if(vs0[e.u]==vs0[e.v]){
                        if(vs0[e.u])v1.pb(e.i);
                        else v2.pb(e.i);
                    }
                }
                for(auto e:vec){
                    if(vs0[e.u]!=vs0[e.v]){
                        if(v1.size()<v2.size())v1.pb(e.i);
                        else v2.pb(e.i);
                    }
                }
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(cnt[i]==1){
                assert(cnt[to[i]]==1);
                if(i<to[i])v1.pb(i);
                else v2.pb(i);
            }
        }
        for(auto e:v1)cout<<e<<" ";
        cout<<"\n";
    }
}

詳細信息

Test #1:

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

input:

2
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
3 2
1 2
2 3

output:

3 4 5 
2 

result:

ok ok (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 34ms
memory: 25408kb

input:

10000
2 1
1 2
29 28
13 19
16 5
21 7
22 10
10 2
1 18
27 13
10 3
11 23
12 22
11 7
7 17
29 17
9 1
28 21
2 18
13 9
4 25
20 16
5 14
20 7
14 4
12 8
8 24
17 19
15 1
11 6
26 9
13 12
13 9
12 2
6 12
9 11
5 2
8 10
6 10
3 10
7 1
7 5
8 9
4 1
12 11
10 6
2 8
12 4
5 10
11 1
3 1
10 1
12 9
9 1
8 3
7 1
35 35
13 8
34 1...

output:

1 
11 20 19 29 1 2 3 4 5 8 9 12 13 21 
5 10 11 13 1 6 
1 8 4 5 6 9 
21 24 27 4 12 20 25 16 1 2 6 10 11 14 17 19 22 
9 11 6 7 8 13 1 2 3 
2 
4 2 
4 10 49 11 15 26 32 21 1 2 5 6 8 12 16 18 19 23 25 29 30 34 36 38 41 
5 26 32 34 4 7 9 16 28 35 11 3 10 14 17 19 24 25 
1 5 4 13 14 2 9 
9 11 2 6 1 3 4 8 1...

result:

wrong answer vertex 1 is not covered (test case 319)