Submission #451213

# Submission time Handle Problem Language Result Execution time Memory
451213 2021-08-03T06:41:28 Z ak2006 Pipes (CEOI15_pipes) C++14
10 / 100
1430 ms 28016 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
int maxN = 1e5 + 5,maxM = 6e6 + 5,n,m,TIMER;
struct DSU
{
    vi p;
    DSU(int _n)
    {
        p.assign(n + 1,-1);
        for (int i = 1;i<=n;i++)p[i] = i;
    }
    int Find(int a)
    {
        if (p[a] == a)return a;
        return p[a] = Find(p[a]);
    }
    bool Merge(int a,int b)
    {
        a = Find(a),b = Find(b);
        if (a == b)return false;

        p[b] = a;
        return true;
    }
};
vvi adj(2 * maxN);
vb vis(maxN);
vi low(maxN),in(maxN);
vvi bridges;
void dfs(int u,int p)
{   
    vis[u] = 1;
    in[u] = low[u] = ++TIMER;
    for (int v:adj[u]){
        if (v == p)continue;
        if (vis[v]){
            low[u] = min(low[u],in[v]);
            continue;
        }        
        dfs(v,u);
        low[u] = min(low[u],low[v]);
        if (low[v] > in[u])
            bridges.pb({u,v});
    }
}
int main()

{
    setIO();
    cin>>n>>m;
    DSU TWOcc(n + 1),cc(n + 1);
    vvi edges;
    for (int i = 1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        if (cc.Find(u) != cc.Find(v)){
            cc.Merge(u,v);
            edges.pb({u,v});
        }
        else if (TWOcc.Find(u) != TWOcc.Find(v)){
            TWOcc.Merge(u,v);
            edges.pb({u,v});
        }
        else continue;
        assert((int)edges.size() <= 2 * n - 2);
    }
    m = (int)edges.size();
    for (auto it:edges){
        //cout<<it[0]<<" "<<it[1]<<endl;
        adj[it[0]].pb(it[1]),adj[it[1]].pb(it[0]);
    }
    for (int i = 1;i<=n;i++)if (!vis[i])dfs(i,-1);
    for (auto it:bridges)cout<<it[0]<<" "<<it[1]<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Incorrect 5 ms 5708 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6792 KB Output is correct
2 Incorrect 9 ms 6536 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 131 ms 6604 KB Output is correct
2 Incorrect 130 ms 6340 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 223 ms 7944 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 349 ms 11004 KB Output is correct
2 Correct 343 ms 10464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 508 ms 21564 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 780 ms 23768 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1050 ms 28016 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1205 ms 28008 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1430 ms 26908 KB Memory limit exceeded
2 Halted 0 ms 0 KB -