답안 #47004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47004 2018-04-25T22:55:33 Z iletavcioski Pipes (CEOI15_pipes) C++17
0 / 100
1245 ms 33256 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> p1(100001,-1);
vector<int> p2(100001,-1);
vector<bool> vis;
vector<pair<int,int> > vk;
vector<vector<int> > v; 
vector<int> rednibroj;
int edges=0;
int broj=1;
int dsu1(int x)
{
    int px=x;
    while(p1[x]!=-1)
        x=p1[x];
    int y=x;
    while(px!=y)
    {
        int xx=p1[px];
        p1[px]=y,px=xx;
    }
    return x;
}
int dsu2(int x)
{
    int px=x;
    while(p2[x]!=-1)
        x=p2[x];
    int y=x;
    while(px!=y)
    {
        int xx=p2[px];
        p2[px]=y,px=xx;
    }
    return x;
}
int bridges(int x,int prev,int broj)
{
    rednibroj[x]=broj;
    int minbr=broj;
    int maxi=0;
    int granki=0;
    for(int i=0;i<v[x].size();i++)
    {
        if(v[x][i]==prev)
            continue;
        if(rednibroj[v[x][i]])
            minbr=min(minbr,rednibroj[v[x][i]]);
        else
        {
            int t=bridges(v[x][i],x,broj+1);
            maxi=max(maxi,t);
            minbr=min(minbr,t);
            granki++;
        }
    }
    if(maxi>=rednibroj[x])
    {
        if(x>=edges)
            vis[x-edges]=true;
    }
    return minbr;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        int x=dsu1(a);
        int y=dsu1(b);
        if(x!=y)
        {
            p1[x]=y;
            vk.push_back(make_pair(a,b));
            vis.push_back(0);
            edges++;
        }
        else
        {
            int x1=dsu2(a);
            int y1=dsu2(b);
            if(x1!=y1)
            {
                p2[x1]=y1;
                vk.push_back(make_pair(a,b));
                vis.push_back(0);
                edges++;
            }

        }
    }
    p1.clear();
    p2.clear();
    vector<int> vec;
    v.insert(v.begin(),(n+edges+16),vec);
    for(int i=0;i<(n+edges+17);i++)
    {
        rednibroj.push_back(0);
    }
    int br=edges;
    for(int i=0;i<edges;i++)
    {
        pair<int,int> p=vk[i];
        v[p.first].push_back(br);
        v[br].push_back(p.first);
        v[br].push_back(p.second);
        v[p.second].push_back(br);
        br++;
    }
    for(int i=0;i<n;i++)
    {
        if(!rednibroj[i])
        {
            bridges(i,-1,1);
        }
    }
    for(int i=0;i<edges;i++)
    {
        if(vis[i])
        {
            cout<<vk[i].first+1<<" "<<vk[i].second+1<<endl;
        }
    }
    return 0;
}

Compilation message

pipes.cpp: In function 'int bridges(int, int, int)':
pipes.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 3216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 176 ms 5064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 299 ms 9480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 437 ms 23920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 643 ms 27328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 845 ms 33144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1089 ms 33256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1245 ms 31640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -