Submission #1021720

#TimeUsernameProblemLanguageResultExecution timeMemory
1021720idiotcomputerPipes (CEOI15_pipes)C++11
50 / 100
781 ms47492 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz size const int mxN = 1e5; int n,m; vector<int> adj[mxN]; int p[2*mxN]; void dfs(int c, int depth, int par){ p[c] = depth; p[c+n] = p[c]; int op = par; for (int i : adj[c]){ if (i == par){par = -1; continue;} if (p[i] != -1){ p[c+n] = min(p[c+n],p[i]); continue;} dfs(i,depth+1,c); p[c+n] = min(p[c+n], p[i+n]); } if (p[c+n] >= depth && op != -1) cout << c+1 << " " << op+1 << '\n'; } int gpar(const int &c){ if (p[c] == c) return c; p[c] = gpar(p[c]); return p[c]; } bool ss(const int &a, const int &b){ return gpar(a) == gpar(b); } void un(const int &a, const int &b){ p[gpar(a)] = gpar(b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < 2* n; i++) p[i] = i; int a,b; for (int i = 0; i < m; i++){ cin >> a >> b; a -= 1; b -= 1; if (!ss(a,b)) un(a,b); else if (!ss(a+n,b+n)) un(a+n,b+n); else continue; adj[a].pb(b); adj[b].pb(a); } for (int i = 0; i < n; i++) p[i] = -1; for (int i = 0; i < n; i++) if (p[i] == -1) dfs(i,0,-1); return 0; }
#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...