Submission #147280

#TimeUsernameProblemLanguageResultExecution timeMemory
147280luciocfPotemkin cycle (CEOI15_indcyc)C++14
50 / 100
1070 ms102632 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int maxn = 1e3+10; const int maxm = 1e5+10; const int inf = 1e9+10; int mat[maxn][maxn]; int dist[maxn], pai[maxn][maxn]; pii edge[maxm]; int minimo[maxm], pivot[maxm]; bool nope[maxm][maxn]; bool mark[maxn]; vector<pii> grafo[maxn]; void bfs(int x) { memset(dist, -1, sizeof dist); queue<int> fila; dist[x] = 0, pai[x][x] = 0, fila.push(x); while (!fila.empty()) { int u = fila.front(); fila.pop(); for (auto pp: grafo[u]) { int v = pp.first, e = pp.second; if (dist[v] == -1) { dist[v] = dist[u]+1, pai[x][v] = u; fila.push(v); } else if (v != pai[x][u] && !nope[e][pai[x][u]] && !nope[e][pai[x][v]]) { if (dist[u]+dist[v]+1 < minimo[e]) { minimo[e] = dist[u]+dist[v]+1; pivot[e] = x; } } } } } int main(void) { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); mat[u][v] = mat[v][u] = 1; edge[i] = {u, v}; grafo[u].push_back({v, i}); grafo[v].push_back({u, i}); minimo[i] = inf; } for (int u = 1; u <= n; u++) { for (auto pp: grafo[u]) { int v = pp.first, e = pp.second; for (int w = 1; w <= n; w++) if (w != u && w != v && mat[w][u] && mat[w][v]) nope[e][w] = 1; } } for (int i = 1; i <= n; i++) bfs(i); for (int i = 1; i <= m; i++) { if (minimo[i] != inf) { memset(mark, 0, sizeof mark); int u = edge[i].first, v = edge[i].second; vector<int> ans, aux; bool ok = 1; mark[pivot[i]] = 1; while (u != pivot[i]) { if (mark[u]) ok = 0; mark[u] = 1; ans.push_back(u); u = pai[pivot[i]][u]; } ans.push_back(pivot[i]); while (v != pivot[i]) { if (mark[v]) ok = 0; mark[v] = 1; aux.push_back(v); v = pai[pivot[i]][v]; } if (!ok) continue; reverse(aux.begin(), aux.end()); for (auto x: aux) ans.push_back(x); for (auto x: ans) printf("%d ", x); printf("\n"); return 0; } } printf("no\n"); }

Compilation message (stderr)

indcyc.cpp: In function 'int main()':
indcyc.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
#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...