Submission #872690

#TimeUsernameProblemLanguageResultExecution timeMemory
872690Ghulam_JunaidPipes (CEOI15_pipes)C++17
0 / 100
912 ms65536 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int par1[N], par2[N], h[N], mnh[N]; bool vis[N]; vector<int> g[N]; vector<pair<int, int>> bridges; int root1(int v){ return (par1[v] == -1 ? v : par1[v] = root1(par1[v])); } int root2(int v){ return (par2[v] == -1 ? v : par2[v] = root2(par2[v])); } void merge1(int u, int v){ int r1 = root1(v); int r2 = root1(u); par1[r1] = r2; g[v].push_back(u); g[u].push_back(v); } void merge2(int u, int v){ int r1 = root2(u); int r2 = root2(v); if (r1 == r2) return; par2[r1] = r2; g[v].push_back(u); g[u].push_back(v); } void dfs(int v, int p = -1){ vis[v] = 1; mnh[v] = h[v]; for (int u : g[v]){ if (vis[u]){ if (u != p) mnh[v] = min(mnh[v], h[u]); continue; } h[u] = h[v] + 1; dfs(u, v); mnh[v] = min(mnh[v], mnh[u]); if (mnh[u] >= h[u]) bridges.push_back({u, v}); } } int main(){ int n, m; scanf("%d%d", &n, &m); for (int i=1; i<=n; i++) par1[i] = par2[i] = -1; for (int i=0; i<m; i++){ int u, v; scanf("%d%d", &u, &v); if (root1(u) == root1(v)) merge2(u, v); else merge1(u, v); } for (int v = 1; v <= n; v++) if (!vis[v]) dfs(v); for (auto [u, v] : bridges) printf("%d %d\n", u, v); }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...