답안 #223897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223897 2020-04-16T20:13:22 Z MKopchev Pipes (CEOI15_pipes) C++14
80 / 100
1898 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)
        {
            if(in[k.first]==0)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 11 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 4344 KB Output is correct
2 Correct 157 ms 3772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 4876 KB Output is correct
2 Correct 322 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 6624 KB Output is correct
2 Correct 396 ms 5908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 616 ms 12580 KB Output is correct
2 Correct 541 ms 8580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 967 ms 12800 KB Output is correct
2 Correct 906 ms 9492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1267 ms 15212 KB Output is correct
2 Correct 1196 ms 10960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1559 ms 15608 KB Output is correct
2 Runtime error 1511 ms 64152 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1898 ms 14464 KB Output is correct
2 Runtime error 1814 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)