제출 #115907

#제출 시각아이디문제언어결과실행 시간메모리
115907tutisPotemkin cycle (CEOI15_indcyc)C++17
50 / 100
1078 ms1384 KiB
/*input 5 6 1 2 1 3 2 3 4 3 5 2 4 5 */ #pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; vector<int>adj[1010]; vector<int>x; bool yra[1010]; int pos[1010]; void ieskom(int i, int p) { if (yra[i]) return; pos[i] = x.size(); x.push_back(i); yra[i] = true; int maxi = -1; for (int j : adj[i]) { if (yra[j] && j != p) { maxi = max(maxi, pos[j]); } } if (maxi == -1) for (int j : adj[i]) { ieskom(j, i); } else { vector<int>ciklas; for (int t = maxi; t < (int)x.size(); t++) { ciklas.push_back(x[t]); } if (ciklas.size() >= 4) { for (int i : ciklas) cout << i << " "; exit(0); } } yra[i] = false; x.pop_back(); } int pa[1010]; int root(int x) { if (pa[x] == x) return x; return pa[x] = root(pa[x]); } int main() { ios_base::sync_with_stdio(false); int n, r; cin >> n >> r; for (int i = 1; i <= n; i++) pa[i] = i; while (r--) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); pa[root(a)] = root(b); } vector<int>k[n + 1]; for (int i = 1; i <= n; i++) k[root(i)].push_back(i); for (int i = 1; i <= n; i++) { if (k[i].empty()) continue; for (int t = 0; t < 20; t++) { int j = k[i][rand() % k[i].size()]; ieskom(j, -3); } } cout << "no\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...