Submission #44883

#TimeUsernameProblemLanguageResultExecution timeMemory
44883bogdan10bosPipes (CEOI15_pipes)C++14
100 / 100
1370 ms13396 KiB
#include <bits/stdc++.h> using namespace std; //#define FILE_IO typedef pair<int, int> pii; int N, M; int h[100005], low[100005], vis[100005]; vector<int> edg[100005]; class UnionFind { public: int N; int f[100005]; void init(int _N) { N = _N; for(int i = 1; i <= N; i++) f[i] = i; } int F(int x) { if(f[x] == x) return x; return f[x] = F(f[x]); } void unite(int x, int y) { if(F(x) == F(y)) return; f[F(y)] = F(x); } }; UnionFind f[2]; void DFS(int nod, int fth) { h[nod] = h[fth] + 1; low[nod] = h[nod]; vis[nod] = 1; int father = 0; for(auto nxt: edg[nod]) { if(nxt == fth) { father++; if(father == 1) continue; } if(vis[nxt]) { low[nod] = min(low[nod], low[nxt]); continue; } DFS(nxt, nod); low[nod] = min(low[nod], low[nxt]); if(low[nxt] > h[nod]) printf("%d %d\n", nod, nxt); } } int main() { #ifdef FILE_IO freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); #endif scanf("%d%d", &N, &M); f[0].init(N), f[1].init(N); int cnt = 0; for(int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); if(f[1].F(x) == f[1].F(y)) continue; edg[x].push_back(y); edg[y].push_back(x); if(f[0].F(x) != f[0].F(y)) f[0].unite(x, y); else f[1].unite(x, y); } for(int i = 1; i <= N; i++) if(!vis[i]) DFS(i, 0); return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:78:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt = 0;
         ^~~
pipes.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#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...