Submission #382542

# Submission time Handle Problem Language Result Execution time Memory
382542 2021-03-27T15:56:18 Z Mahdi_Shokoufi Pipes (CEOI15_pipes) C++17
70 / 100
1377 ms 63468 KB
//In the name of Allah
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef pair < int , int > pii;

const int N = 1e5 + 10;

int par[2][N];
bitset < N > mark;
vector < pii > adj[N];

int getPar(int t, int v){
    return par[t][v] == v ? v : par[t][v] = getPar(t, par[t][v]);
}

bool merge(int t, int u, int v){
    u = getPar(t, u); v = getPar(t, v);
    if (u == v)
        return false;
    par[t][u] = v;
    return true;
}

void DFS(int v, int p = -1){
    mark[v] = 1;
    par[1][v] = N; //dp[v] = N;
    for (pii e : adj[v]){
        int u = e.X, id = e.Y;
        if (id == p)
            continue;
        if (mark[u])
            par[1][v] = min(par[1][v], par[0][u]); //dp[v] = min(dp[v], h[u]);
        else{
            par[0][u] = par[0][v] + 1; //h[u] = h[v] + 1;
            DFS(u, id);
            par[1][v] = min(par[1][v], par[1][u]); //dp[v] = min(dp[v], dp[u]);
            if (par[0][v] < par[1][u]) //(h[v] < dp[u])
                cout << u << ' ' << v << '\n';
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < N; i ++)
        par[0][i] = par[1][i] = i;
    for (int i = 0; i < m; i ++){
        int u, v;
        cin >> u >> v;
        if (merge(0, u, v)){
            adj[u].pb(mp(v, i));
            adj[v].pb(mp(u, i));
        }
        else if (merge(1, u, v)){
            adj[u].pb(mp(v, i));
            adj[v].pb(mp(u, i));
        }
    }
    memset(par, 0, sizeof par);
    for (int v = 1; v <= n; v ++)
        if (!mark[v])
            DFS(v);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4076 KB Output is correct
2 Correct 7 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 5996 KB Output is correct
2 Correct 118 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 6636 KB Output is correct
2 Correct 246 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 8296 KB Output is correct
2 Correct 280 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 11884 KB Output is correct
2 Correct 403 ms 9324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 13216 KB Output is correct
2 Correct 652 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 929 ms 15596 KB Output is correct
2 Runtime error 933 ms 51968 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1139 ms 15596 KB Output is correct
2 Runtime error 1110 ms 63468 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 1377 ms 16640 KB Memory limit exceeded
2 Halted 0 ms 0 KB -