Submission #476059

#TimeUsernameProblemLanguageResultExecution timeMemory
476059bluePipes (CEOI15_pipes)C++17
20 / 100
5063 ms48816 KiB
#include <iostream> #include <vector> using namespace std; struct disjoint_set { int N; vector<int> parent; vector<int> subtree; int cc; disjoint_set() { ; } disjoint_set(int N_) { N = N_; cc = N; parent = vector<int>(1+N); subtree = vector<int>(1+N, 1); for(int i = 1; i <= N; i++) parent[i] = i; } int root(int u) { int v = u; while(parent[v] != v) v = parent[v]; parent[u] = v; return parent[u]; } bool connected(int u, int v) { return root(u) == root(v); } void join(int u, int v) { u = root(u); v = root(v); if(u == v) return; if(subtree[u] < subtree[v]) swap(u, v); parent[v] = u; subtree[u] += subtree[v]; cc--; } }; int main() { int N, M; cin >> N >> M; int u[M+1], v[M+1]; for(int j = 1; j <= M; j++) cin >> u[j] >> v[j]; disjoint_set basic(N); for(int j = 1; j <= M; j++) basic.join(u[j],v[j]); for(int k = 1; k <= M; k++) { disjoint_set nw(N); for(int j = 1; j <= M; j++) { if(j == k) continue; nw.join(u[j], v[j]); } if(basic.cc != nw.cc) { cout << u[k] << ' ' << v[k] << '\n'; } } }
#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...