Submission #378453

#TimeUsernameProblemLanguageResultExecution timeMemory
378453AriaHPipes (CEOI15_pipes)C++11
100 / 100
1581 ms14316 KiB
/** I can do this all day **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(),(x).end() #define F first #define S second #define Mp make_pair #define SZ(x) (int)x.size() const int N = 1e5 + 5; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 8e18; const int LOG = 22; int par[N * 2]; int get(int x) { return (x == par[x]? x : par[x] = get(par[x])); } int unify(int v, int u) { v = get(v), u = get(u); if(v == u) { return 0; } par[u] = v; return 1; } int n, m, H[N], Up[N]; vector < int > G[N]; void dfs(int v, int P = -1) { Up[v] = H[v]; int id = -1; for(auto u : G[v]) { id ++; if(u == P) continue; if(H[u]) { Up[v] = min(Up[v], H[u]); } else { H[u] = H[v] + 1; dfs(u, v); if(Up[u] > H[v] && (id > 0 && G[v][id - 1] == u) == 0 && (id + 1 < SZ(G[v]) && G[v][id + 1] == u) == 0) { printf("%d %d\n", v, u); } Up[v] = min(Up[v], Up[u]); } } } int main() { for(int i = 0; i < N << 1; i ++) par[i] = i; scanf("%d%d", &n, &m); for(int i = 1; i <= m; i ++) { int a, b; scanf("%d%d", &a, &b); if(unify(a, b)) { G[a].push_back(b); G[b].push_back(a); } else { if(unify(a + n, b + n)) { G[a].push_back(b); G[b].push_back(a); } } } for(int i = 1; i <= n; i ++) sort(all(G[i])); for(int i = 1; i <= n; i ++) { if(H[i]) continue; H[i] = 1; dfs(i); } return 0; } /** test corner cases(n = 1?) watch for overflow or minus indices **/

Compilation message (stderr)

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