Submission #100507

# Submission time Handle Problem Language Result Execution time Memory
100507 2019-03-11T19:56:40 Z doowey Pipes (CEOI15_pipes) C++14
0 / 100
1460 ms 5112 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;

struct DSU{
    int pi[N];
    int sz[N];
    int fin(int x){
        while(x!=pi[x]){
            x=pi[x];
        }
        return x;
    }
    bool unite(int a, int b){
        a = fin(a);
        b = fin(b);
        if(a==b)
            return false;
        if(sz[a] > sz[b])
            swap(a, b);
        sz[b] += sz[a];
        pi[a] = b;
        return true;
    }
    void Init(){
        for(int i = 0 ;i  < N ; i ++ ){
            pi[i] = i;
            sz[i] = 1;
        }
    }
};

DSU A, B;

vector<int> T[N];

int tin[N];
int low[N];
int timer;

bool vis[N];

void dfs(int node, int par){
    vis[node] = true;
    tin[node] = timer ++ ;
    low[node] = tin[node];
    for(auto x : T[node]){
        if(x == par){
            continue;
        }
        if(vis[x]){
            low[node] = min(low[node], tin[x]);
        }
        else{
            dfs(x, node);
            low[node] = min(low[node], low[x]);
            if(tin[node] < low[x] && B.fin(x) != B.fin(node)){
                cout << x << " " << node << "\n";
            }
        }
    }
}



int main(){
    fastIO;
    A.Init();
    B.Init();
    int n, m;
    cin >> n >> m;
    int u, v;
    int cnt = 0;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v;
        if(A.unite(u,v)){
       //     T[u].push_back(v);
        //    T[v].push_back(u);
            cnt += 2 ;
        }
        else if(B.unite(u,v)){
         //   T[u].push_back(v);
         //   T[v].push_back(u);
            cnt += 2;
        }
    }
 //   assert(cnt <= (int)4e5);
    for(int i = 1; i <= n; i ++ )
        if(!vis[i])dfs(i,-1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4224 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4224 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 4296 KB Output is correct
2 Incorrect 114 ms 4316 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 204 ms 4296 KB Output is correct
2 Incorrect 246 ms 4344 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 340 ms 4472 KB Output is correct
2 Incorrect 292 ms 4600 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 466 ms 4820 KB Output is correct
2 Incorrect 392 ms 4856 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 729 ms 4956 KB Output is correct
2 Incorrect 733 ms 4948 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 937 ms 5068 KB Output is correct
2 Incorrect 893 ms 5064 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1175 ms 5064 KB Output is correct
2 Incorrect 1157 ms 5112 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1460 ms 5068 KB Output is correct
2 Incorrect 1403 ms 5068 KB Wrong number of edges