Submission #47005

#TimeUsernameProblemLanguageResultExecution timeMemory
47005iletavcioskiPipes (CEOI15_pipes)C++17
50 / 100
1415 ms37596 KiB
#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(),5*n,vec); for(int i=0;i<5*n;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 (stderr)

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++)
                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...