Submission #386360

# Submission time Handle Problem Language Result Execution time Memory
386360 2021-04-06T12:57:08 Z FatihSolak Pipes (CEOI15_pipes) C++17
40 / 100
1592 ms 25452 KB
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int par[N][2];
int find(int a,int val){
    if(par[a][val] == a)return a;
    return par[a][val] = find(par[a][val],val);
}
vector<int> adj[N];
map<pair<int,int>,int> mp;
bool merge(int a,int b,int val){
    int tmp1 = a,tmp2 = b;
    a = find(a,val);
    b = find(b,val);
    if(a == b)return 0;
    par[a][val] = b;
    adj[tmp1].push_back(tmp2);
    adj[tmp2].push_back(tmp1);
    if(val){
        mp[{tmp1,tmp2}] = 1;
        mp[{tmp2,tmp1}] = 1;
    }
    return 1;
}
int n;
vector<bool> visited;
vector<int> tin, low;
int timer;
void IS_BRIDGE(int v,int a){
    if(!mp[{v,a}])
    cout << v << " " << a << endl;
}
void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : adj[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v])
                IS_BRIDGE(v, to);
        }
    }
}

void find_bridges() {
    timer = 0;
    visited.assign(N, false);
    tin.assign(N, -1);
    low.assign(N, -1);
    for (int i = 1; i <= n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}
void solve(){
    int m;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        par[i][0] = par[i][1] = i;
    }
    int l,r;
    for(int i=1;i<=m;i++){
        cin >> l >> r;
        if(!merge(l,r,0))
            merge(l,r,1);
    }
    find_bridges();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3436 KB Output is correct
2 Correct 3 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4460 KB Output is correct
2 Correct 10 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4332 KB Output is correct
2 Correct 111 ms 4076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 5564 KB Output is correct
2 Runtime error 240 ms 16492 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 351 ms 8752 KB Output is correct
2 Correct 291 ms 7356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 567 ms 18948 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 888 ms 21228 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1117 ms 25452 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1338 ms 25452 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1592 ms 24228 KB Memory limit exceeded
2 Halted 0 ms 0 KB -