Submission #365989

#TimeUsernameProblemLanguageResultExecution timeMemory
365989kostia244Potemkin cycle (CEOI15_indcyc)C++17
90 / 100
844 ms6516 KiB
#include<bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int maxn = 1002, maxm = 2e5 + 3; int can[maxm][maxn], hv[maxn][maxn], vis[maxm], n, m; vector<array<int, 2>> edges; vector<int> cur; void reduce() { int r = 0; while(r < cur.size()) { int ok = 1; for(int i = 1; i+1 < r; i++) { ok &= !hv[cur[r]][cur[i]]; } if(!ok) break; if(r > 1 && hv[cur[r]][cur[0]]) {r++;break;} r++; } for(int i = 0; i < r; i++) cout << cur[i] << " "; cout << endl; exit(0); } void dfs(int ed) { vis[ed] = 2; auto [st, en] = edges[ed]; cur.push_back(en); for(int i = 1; i <= n; i++) if(i != st && i != en) { if(hv[i][en] && hv[i][st]) continue; if(!hv[en][i]) continue; if(!vis[hv[en][i]-1]) { dfs(hv[en][i]-1); } else if(vis[hv[en][i]-1] == 2) { reverse(all(cur)); while(cur.back() != en) cur.pop_back(); cur.pop_back(); reduce(); } } vis[ed] = 1; cur.pop_back(); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; edges.resize(m); for(auto &[f, t] : edges) { cin >> f >> t; } for(int i = 0; i < m; i++) edges.push_back({edges[i][1], edges[i][0]}); for(int i = 0; i < 2*m; i++) hv[edges[i][0]][edges[i][1]] = i+1; for(int i = 0; i < 2*m; i++) if(!vis[i]) { cur = {edges[i][0]}; dfs(i); } cout << "no\n"; }

Compilation message (stderr)

indcyc.cpp: In function 'void reduce()':
indcyc.cpp:11:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  while(r < cur.size()) {
      |        ~~^~~~~~~~~~~~
indcyc.cpp:20:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   20 |  for(int i = 0; i < r; i++) cout << cur[i] << " "; cout << endl;
      |  ^~~
indcyc.cpp:20:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   20 |  for(int i = 0; i < r; i++) cout << cur[i] << " "; cout << endl;
      |                                                    ^~~~
#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...