답안 #223896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223896 2020-04-16T20:11:23 Z MKopchev Pipes (CEOI15_pipes) C++14
60 / 100
1840 ms 52172 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)]=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);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3328 KB Output is correct
2 Correct 12 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 3832 KB Output is correct
2 Correct 156 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 4408 KB Output is correct
2 Correct 318 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 6008 KB Output is correct
2 Correct 372 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 599 ms 12280 KB Output is correct
2 Correct 518 ms 8440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 12152 KB Output is correct
2 Runtime error 911 ms 42488 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1231 ms 14360 KB Output is correct
2 Runtime error 1219 ms 52172 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1506 ms 18260 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1840 ms 30652 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -