Submission #1111852

#TimeUsernameProblemLanguageResultExecution timeMemory
1111852Ghulam_JunaidPotemkin cycle (CEOI15_indcyc)C++17
70 / 100
1082 ms3212 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m, par[N]; bool is_edge[N][N], vis[N]; vector<int> g[N]; vector<pair<int, int>> edges; void bfs(int id){ auto [x, y] = edges[id]; memset(vis, 0, sizeof vis); memset(par, -1, sizeof par); for (int z = 1; z <= n; z ++) vis[z] = (is_edge[x][z] and is_edge[z][y]); queue<int> q; q.push(x); vis[x] = 1; while (!q.empty()){ int v = q.front(); q.pop(); for (int e : g[v]){ if (e == id) continue; int u = edges[e].first + edges[e].second - v; if (vis[u]) continue; par[u] = v; vis[u] = 1; q.push(u); } } } int main(){ cin >> n >> m; for (int e = 0; e < m; e ++){ int u, v; cin >> u >> v; edges.push_back({u, v}); g[u].push_back(e); g[v].push_back(e); is_edge[u][v] = is_edge[v][u] = 1; } for (int e = 0; e < m; e ++){ bfs(e); auto [u, v] = edges[e]; if (vis[u] and vis[v]){ while (v != u){ cout << v << " "; v = par[v]; } cout << u << endl; return 0; } } cout << "no" << 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...