Submission #382528

# Submission time Handle Problem Language Result Execution time Memory
382528 2021-03-27T15:17:51 Z Mahdi_Shokoufi Pipes (CEOI15_pipes) C++17
40 / 100
1355 ms 65536 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], sz[2][N], mark[N], h[N], dp[N];
vector < pii > adj[N], ans;

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;
    if (sz[t][v] < sz[t][u])
        swap(u, v);
    par[t][u] = v;
    sz[t][v] += sz[t][u];
    return true;
}

void DFS(int v, int p = -1){
    mark[v] = 1;
    dp[v] = N;
    for (pii e : adj[v]){
        int u = e.X, id = e.Y;
        if (id == p)
            continue;
        if (mark[u])
            dp[v] = min(dp[v], h[u]);
        else{
            h[u] = h[v] + 1;
            DFS(u, id);
            dp[v] = min(dp[v], dp[u]);
            if (h[v] < dp[u])
                ans.pb(mp(u, v));
        }
    }
}

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, sz[0][i] = sz[1][i] = 1;
    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));
        }
    }
    for (int v = 1; v <= n; v ++)
        if (!mark[v])
            DFS(v);
    for (pii e : ans)
        cout << e.X << ' ' << e.Y << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4204 KB Output is correct
2 Correct 4 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4972 KB Output is correct
2 Correct 7 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 10220 KB Output is correct
2 Correct 114 ms 9964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 15232 KB Output is correct
2 Correct 226 ms 16364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 318 ms 23788 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 433 ms 34284 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 668 ms 48116 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 908 ms 61188 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1088 ms 60500 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1355 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -