Submission #460986

#TimeUsernameProblemLanguageResultExecution timeMemory
460986kingfran1907Potemkin cycle (CEOI15_indcyc)C++14
0 / 100
390 ms5184 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 1010; const int base = 31337; const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int logo = 18; const int off = 1 << logo; const int treesiz = off << 1; int n, m; vector< int > graph[maxn]; int eg[maxn][maxn]; int dis[maxn]; queue< int > q; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); graph[a].push_back(b); graph[b].push_back(a); eg[a][b] = eg[b][a] = 1; } for (int i = 1; i <= n; i++) { for (int j = 0; j < graph[i].size(); j++) { for (int k = j + 1; k < graph[i].size(); k++) { int x = graph[i][j]; int y = graph[i][k]; if (eg[x][y]) continue; for (int i = 1; i <= n; i++) dis[i] = inf; dis[i] = -1; for (int tren : graph[i]) dis[tren] = -1; dis[y] = inf; dis[x] = 0; q.push(x); while (!q.empty()) { int x = q.front(); q.pop(); for (int tren : graph[x]) { if (dis[tren] == inf) { dis[tren] = 1 + dis[x]; q.push(tren); } } } if (dis[y] == inf) continue; vector< int > v; int ptr = y; while (ptr != x) { v.push_back(ptr); for (int tren : graph[ptr]) { if (dis[tren] + 1 == dis[ptr]) { ptr = tren; break; } } } printf("%d %d ", i, x); for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); printf("\n"); return 0; } } } printf("no\n"); return 0; }

Compilation message (stderr)

indcyc.cpp: In function 'int main()':
indcyc.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for (int j = 0; j < graph[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~
indcyc.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for (int k = j + 1; k < graph[i].size(); k++) {
      |                        ~~^~~~~~~~~~~~~~~~~
indcyc.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
indcyc.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
#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...