QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637031#9453. Graph Generatorucup-team5141#AC ✓171ms13480kbC++203.4kb2024-10-13 06:22:062024-10-13 06:22:08

Judging History

你现在查看的是测评时间为 2024-10-13 06:22:08 的历史记录

  • [2024-10-14 16:54:46]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:170ms
  • 内存:13356kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-13 06:22:08]
  • 评测
  • 测评结果:100
  • 用时:171ms
  • 内存:13480kb
  • [2024-10-13 06:22:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>

using ll = long long;
using lf = long double;
int n, m;
vector<int>adj[200005];
int numberEdges[200005];
bool alreadySolved[200005];
bool vis[200005];
bool isPosible;
int rep[200005];
vector<int>past;

void visit(int u){
    vis[u] = true;
    past.pb(u);
}

void restart_visit(){
    for(auto &u : past){
        vis[u] = false;
    }
    past.clear();
}

pair<int, int>farthest(int u, int &size){
    queue<pair<int, int> >cola;
    size = 1;
    cola.push({0, u});
    visit(u);
    int dist;
    pair<int, int>maxi ;
    while(!cola.empty()){
        u = cola.front().ss;
        dist = cola.front().ff;
        maxi = cola.front();
        cola.pop();
        for(auto &v : adj[u]){
            if(vis[v])continue;
            size ++ ;
            visit(v);
            cola.push({dist + 1, v});
        }
    }
    return maxi;
}

vector<pair<int, vector<int> > >answer;

void remove(int u ){
    //cout << "removing " << u << endl;
    vector<int>edges;
    for(auto &v : adj[u]){
        if(vis[v] || alreadySolved[v])continue;
        numberEdges[v] --;
        edges.pb(v);
    }
    vis[u] = true;
    alreadySolved[u] = true;
    answer.pb({u, edges});
}



bool try_solve(int u){
    //cout << "solving " << u << endl;
    int sz = 0;
    pair<int, int> pp = farthest(u, sz);
    if(pp.ff > 2){
        isPosible = false;
        return false;
    }

    for(auto &v : past){
        if(numberEdges[v] == sz - 1){
            //cout << "v = " << v << endl;
            restart_visit();
            remove(v);
            return true;
        }
    }

    isPosible = false;
    return false;


}

int findd(int u){
    if(rep[u] == u)return u;
    return rep[u] = findd(rep[u]);
}

void joinn(int a, int b){
    a = findd(a);
    b = findd(b);
    if(a == b)return ;
    rep[b] = a;
}

void tc(){
    cin >> n >> m;
    answer.clear();
    past.clear();
    for(int i = 1 ; i <= n ; i ++){
        alreadySolved[i] = false;
        adj[i].clear();
        vis[i] = false;
        numberEdges[i] = 0;
        rep[i] = i;

    }
    isPosible = true;
    for(int i = 0 ; i < m ; i ++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        numberEdges[u] ++ ;
        numberEdges[v] ++ ;
    }

    for(int i = 1 ; i <= n ; i ++){
        while(!alreadySolved[i]){
            if(!try_solve(i)){
                break;
            }
        }
        if(!isPosible)break;
    }
    if(!isPosible){
        cout << "No\n";
        return;
    }

    cout << "Yes\n";
    reverse(answer.begin(), answer.end());
    for(int i = 0 ; i < answer.size() ; i ++){
        vector<int>rta ;
        
        for(auto &v : answer[i].ss){
            int a = findd(answer[i].ff), b = findd(v);
            if(a != b){
                rta.pb(v);
                joinn(a, b);
            } 
        }
        cout << answer[i].ff << " " <<rta.size() << " ";
        for(auto &v : rta){
            cout << v << " ";
        }
        cout << "\n";
    }
    
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    #endif

    int t;
    cin >> t;
    while(t--){
        tc();
    }
    return 0;
}

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

詳細信息

Test #1:

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

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
4 0 
3 1 4 
1 0 
2 2 1 3 
No

result:

ok 3 cases passed

Test #2:

score: 0
Accepted
time: 171ms
memory: 13480kb

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
10 0 
9 0 
8 0 
7 1 10 
6 0 
5 0 
4 2 5 6 
3 1 7 
2 1 9 
1 4 4 9 8 10 
No
No
No
Yes
6 0 
5 0 
4 1 5 
3 1 5 
2 1 3 
1 2 2 6 
No
No
Yes
7 0 
6 0 
5 1 6 
4 1 6 
3 1 7 
2 0 
1 3 4 2 7 
Yes
10 0 
9 0 
8 0 
7 0 
6 0 
5 0 
4 0 
3 2 6 10 
2 5 5 10 7 9 8 
1 2 8 4 
Yes
9 0 
8 0 
7 0 
6 0 
5 2 7 8 
4 0 
3 ...

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed