Submission #898897

#TimeUsernameProblemLanguageResultExecution timeMemory
898897duckindogLogičari (COCI21_logicari)C++14
10 / 110
23 ms7772 KiB
// from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; vector<int> ad[N]; int low[N], num[N], it; vector<int> circle; bool dd[N]; void dfs(int u, int pre = 0) { num[u] = low[u] = ++it; int mku, mkv; for (int v : ad[u]) { if (v == pre) continue; if (num[v]) low[u] = min(low[u], num[v]); else { dfs(v, u); low[u] = min(low[u], low[v]); } if (low[v] != num[v]) { if (!dd[u]) circle.push_back(u); if (!dd[v]) circle.push_back(v); dd[u] = dd[v] = 1; } } } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n; bool sub = 1; for (int i = 1; i <= n; ++i) { int u, v; cin >> u >> v; ad[u].push_back(v); ad[v].push_back(u); if (ad[u].size() > 2 || ad[v].size() > 2) sub = 0; } if (sub) { cout << (n % 4 == 0 ? n / 2 : -1); return 0; } dfs(1, 0); for (int x : circle) cout << x << ' '; }

Compilation message (stderr)

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:14:7: warning: unused variable 'mku' [-Wunused-variable]
   14 |   int mku, mkv;
      |       ^~~
Main.cpp:14:12: warning: unused variable 'mkv' [-Wunused-variable]
   14 |   int mku, mkv;
      |            ^~~
Main.cpp: In function 'int32_t main()':
Main.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...