Submission #959109

#TimeUsernameProblemLanguageResultExecution timeMemory
959109Cyber_WolfPipes (CEOI15_pipes)C++17
50 / 100
882 ms48996 KiB
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int N = 1e5+5; vector<vector<int>> adj; vector<int> tin; vector<array<int, 2>> par; int n, m, tmp; int get(int src, int t) { if(src == par[src][t]) return src; return par[src][t] = get(par[src][t], t); } bool join(int u, int v, int t) { u = get(u, t), v = get(v, t); if(u == v) return false; par[u][t] = v; return true; } int dfs(int src, int pa = -1) { int low, idx = 0; tin[src] = low = ++tmp; for(auto it : adj[src]) { if(it == pa) { idx++; continue; } if(tin[it]) { low = min(low, tin[it]); idx++; continue; } int low_it = dfs(it, src); low = min(low, low_it); if(idx && adj[src][idx-1] == it) { idx++; continue; } if(idx+1 < adj[src].size() && adj[src][idx+1] == it) { idx++; continue; } if(low_it > tin[src]) { cout << src << ' ' << it << endl; } idx++; } return low; } int main() { fastio; cin >> n >> m; adj = vector<vector<int>> (n+1); par = vector<array<int, 2>> (n+1); tin = vector<int> (n+1); for(int i = 1; i <= n; i++) par[i] = {i, i}; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; if(join(u, v, 0) || join(u, v, 1)) { adj[u].push_back(v), adj[v].push_back(u); } } for(int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end()); for(int i = 1; i <= n; i++) { if(!tin[i]) dfs(i); } return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int dfs(int, int)':
pipes.cpp:52:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   if(idx+1 < adj[src].size() && adj[src][idx+1] == it)
      |      ~~~~~~^~~~~~~~~~~~~~~~~
#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...