Submission #223895

# Submission time Handle Problem Language Result Execution time Memory
223895 2020-04-16T20:10:06 Z MKopchev Pipes (CEOI15_pipes) C++14
40 / 100
1850 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+42;

vector< pair<int/*to*/,int/*id*/> > adj[nmax];

int in[nmax],low[nmax],t=0;

int n,m;

void dfs(int node,int par_edge)
{
    if(in[node])return;

    t++;
    in[node]=t;
    low[node]=t;
    //cout<<t<<" -> "<<node<<endl;
    for(auto k:adj[node])
        if(k.second!=par_edge)
        {
            dfs(k.first,k.second);

            //cout<<"finished "<<node<<" "<<k.first<<" "<<low[k.first]<<endl;

            if(in[node]<in[k.first]&&in[node]<low[k.first])
            {
                printf("%i %i\n",node,k.first);
            }
            else low[node]=min(low[k.first],low[node]);
        }
}

int parent[2][nmax];

int root(int id,int node)
{
    if(parent[id][node]==node)return node;
    parent[id][node]=root(id,parent[id][node]);
    return parent[id][node];
}
int main()
{
    scanf("%i%i",&n,&m);

    for(int i=1;i<=n;i++)
    {
        parent[0][i]=i;
        parent[1][i]=i;
    }

    int u,v;
    for(int i=1;i<=m;i++)
    {
        scanf("%i%i",&u,&v);

        bool keep=0;
        for(int j=0;j<2;j++)
        {
            if(root(j,u)==root(j,v))continue;

            parent[j][root(j,u)]=parent[j][root(j,v)];
            keep=1;
            break;
        }

        if(keep==0)continue;

        adj[u].push_back({v,i});
        adj[v].push_back({u,i});


    }

    //cout<<" --- "<<endl;
    for(int i=1;i<=n;i++)
        if(in[i]==0)dfs(i,0);

    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3200 KB Output is correct
2 Correct 11 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 3192 KB Output is correct
2 Correct 160 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 3704 KB Output is correct
2 Correct 327 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 5496 KB Output is correct
2 Runtime error 386 ms 19064 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 603 ms 15480 KB Output is correct
2 Runtime error 550 ms 26592 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Runtime error 940 ms 45080 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 1239 ms 58104 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 1524 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 1850 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -