Submission #527113

#TimeUsernameProblemLanguageResultExecution timeMemory
527113maomao90Potemkin cycle (CEOI15_indcyc)C++17
20 / 100
340 ms5576 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i, j, k) for (int i = j; i < k; i++) #define RREP(i, j, k) for (int i = j; i >= k; i--) template<class T> inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;} template<class T> inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;} typedef long long ll; #define FI first #define SE second #define MP make_pair typedef pair<int, int> ii; #define pb push_back #define ALL(x) x.begin(), x.end() typedef vector<int> vi; typedef vector<ii> vii; #ifndef DEBUG #define cerr if (0) cerr #endif #define MAXN 1005 #define INF 1000000005 #define LINF 1000000000000000005ll int n, r; vi adj[MAXN]; int grid[MAXN][MAXN]; vii eg; int uf[MAXN], rnk[MAXN]; int findp(int i) { if (uf[i] == i) return i; return uf[i] = findp(uf[i]); } bool join(int a, int b) { int pa = findp(a), pb = findp(b); if (pa == pb) return 0; if (rnk[pa] < rnk[pb]) swap(pa, pb); if (rnk[pa] == rnk[pb]) rnk[pa]++; uf[pb] = pa; return 1; } int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n >> r; REP (i, 0, n + 1) { uf[i] = i; } REP (i, 0, r) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); grid[a][b] = grid[b][a] = 1; eg.pb(MP(a, b)); } for (auto [a, b] : eg) { REP (i, 1, n + 1) { if (grid[i][a] == 1 && grid[i][b] == 1) { join(i, a); join(i, b); } } } return 0; }
#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...