답안 #47006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47006 2018-04-25T23:05:54 Z iletavcioski Pipes (CEOI15_pipes) C++17
100 / 100
1350 ms 15352 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> p1(100001,-1);
vector<int> p2(100001,-1);
vector<vector<pair<int,int> > > v; 
vector<int> lo;
vector<int> ind;
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;
}
void bridges(int x,int prev,int broj)
{
    lo[x]=broj;
    ind[x]=broj;
    for(int i=0;i<v[x].size();i++)
    {
        if(v[x][i].second==prev)
            continue;
        if(ind[v[x][i].first]==-1)
        {
            bridges(v[x][i].first,v[x][i].second,broj+1);
            lo[x]=min(lo[x],lo[v[x][i].first]);
            if(lo[v[x][i].first]>ind[x])
            {
                cout<<x+1<<" "<<v[x][i].first+1<<endl;
            }
        }
        else
            lo[x]=min(lo[x],ind[v[x][i].first]);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> > vec;
    v.insert(v.begin(),n,vec);
    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;
            v[a].push_back(make_pair(b,edges));
            v[b].push_back(make_pair(a,edges));
            edges++;
        }
        else
        {
            int x1=dsu2(a);
            int y1=dsu2(b);
            if(x1!=y1)
            {
                p2[x1]=y1;
                v[a].push_back(make_pair(b,edges));
                v[b].push_back(make_pair(a,edges));
                edges++;
            }

        }
    }
    p1.clear();
    p2.clear();
    for(int i=0;i<n;i++)
    {
        lo.push_back(0);
        ind.push_back(-1);
    }
    for(int i=0;i<n;i++)
    {
        if(ind[i]==-1)
        {
            bridges(i,-1,1);
        }
    }
    return 0;
}

Compilation message

pipes.cpp: In function 'void bridges(int, int, int)':
pipes.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1792 KB Output is correct
2 Correct 6 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 1632 KB Output is correct
2 Correct 103 ms 1480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 2532 KB Output is correct
2 Correct 205 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 4584 KB Output is correct
2 Correct 275 ms 4220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 447 ms 11116 KB Output is correct
2 Correct 432 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 12464 KB Output is correct
2 Correct 674 ms 9320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 960 ms 15352 KB Output is correct
2 Correct 835 ms 11060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1074 ms 15232 KB Output is correct
2 Correct 1031 ms 11080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1350 ms 14544 KB Output is correct
2 Correct 1198 ms 11244 KB Output is correct