Submission #169468

# Submission time Handle Problem Language Result Execution time Memory
169468 2019-12-20T14:44:06 Z Andrei_Cotor Pipes (CEOI15_pipes) C++14
0 / 100
5000 ms 5880 KB
#include<iostream>
#include<vector>

using namespace std;

int ParLink[100005],P[100005],Lev[100005],Sz[100005],Low[100005],Covered[100005],Prv[100005];
pair<int,int> Edge[100005];
vector<pair<int,int> > A[100005];

int parentLink(int x)
{
    int cx=x;
    while(ParLink[x]!=0)
        x=ParLink[x];

    while(cx!=0)
    {
        int aux=ParLink[cx];
        ParLink[cx]=x;
        cx=aux;
    }
    return x;
}

void dfs(int nod, int p, int lev, int px)
{
    P[nod]=px;
    Lev[nod]=lev;
    for(auto other:A[nod])
        if(other.first!=p)
        {
            Prv[other.first]=other.second;
            dfs(other.first,nod,lev+1,px);
            Low[parentLink(other.second)]=nod;
        }
}

void unite(int x, int y, int nr)
{
    int px=P[x];
    int py=P[y];
    if(Sz[px]<Sz[py])
    {
        swap(x,y);
        swap(px,py);
    }

    Sz[px]+=Sz[py];

    A[x].push_back({y,nr});
    A[y].push_back({x,nr});

    Prv[y]=nr;
    Low[nr]=x;
    ParLink[nr]=0;
    dfs(y,x,Lev[x]+1,px);
}

void update(int x, int y)
{
    while(x!=y)
    {
        if(Lev[x]<Lev[y])
            swap(x,y);

        Covered[Prv[x]]=1;
        x=Low[parentLink(Prv[x])];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,m;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        Sz[i]=1;
        P[i]=i;
        Lev[i]=1;
    }

    int nr=0;
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        if(P[x]!=P[y])
        {
            nr++;
            Edge[nr]={x,y};
            unite(x,y,nr);
        }
        else
            update(x,y);
    }

    for(int i=1; i<=nr; i++)
        if(!Covered[i])
            cout<<Edge[i].first<<" "<<Edge[i].second<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 5075 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5026 ms 2808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5012 ms 3128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5101 ms 3576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5036 ms 4600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5017 ms 5112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5097 ms 5752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5017 ms 5880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5091 ms 5496 KB Time limit exceeded
2 Halted 0 ms 0 KB -