Submission #154220

# Submission time Handle Problem Language Result Execution time Memory
154220 2019-09-19T11:27:58 Z arnold518 Pipes (CEOI15_pipes) C++14
0 / 100
1854 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 1e5;

struct UF
{
    int par[MAXN+10];
    UF() { for(int i=0; i<=MAXN; i++) par[i]=i; }
    int Find(int x)
    {
        if(x==par[x]) return x;
        return par[x]=Find(par[x]);
    }
    void Union(int x, int y)
    {
        x=Find(x); y=Find(y);
        par[x]=y;
    }
};
UF uf1, uf2;

int N, M;
vector<int> adj[MAXN+10];
vector<pii> ans;

int idx[MAXN+10], cnt=1;

int dfs(int now, int bef)
{
    idx[now]=cnt++;
    int ret=idx[now];
    for(int nxt : adj[now])
    {
        if(nxt==bef) continue;
        if(idx[nxt]!=0) ret=min(ret, idx[nxt]);
        else
        {
            int t=dfs(nxt, now);
            ret=min(ret, t);
            if(t>idx[now]) ans.push_back({now, nxt});
        }
    }
    return ret;
}

int main()
{
    int i, j;

    scanf("%d%d", &N, &M);
    while(M--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        if(uf1.Find(u)!=uf1.Find(v)) uf1.Union(u, v), adj[u].push_back(v), adj[v].push_back(u);
        else if(uf2.Find(u)!=uf2.Find(v)) uf2.Union(u, v), adj[u].push_back(v), adj[v].push_back(u);
    }

    for(i=1; i<=N; i++) if(!idx[i]) dfs(i, i);
    for(auto it : ans) printf("%d %d\n", it.first, it.second);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:53:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
pipes.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Incorrect 5 ms 3448 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4088 KB Output is correct
2 Incorrect 10 ms 3832 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 143 ms 9336 KB Output is correct
2 Incorrect 140 ms 8952 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 14020 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 425 ms 21980 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 617 ms 31264 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 969 ms 44848 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1262 ms 57412 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1552 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1854 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -