Submission #156081

#TimeUsernameProblemLanguageResultExecution timeMemory
156081IOrtroiii전압 (JOI14_voltage)C++14
100 / 100
173 ms21080 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m; vector<int> g[N]; vector<int> tr[N]; int cnt[N]; int ds[N]; int bad; void dfs1(int v, int p) { for (int u : g[v]) { if (u == p) p = 0; else if (ds[u] && ds[u] < ds[v]) { // printf("back edge %d -> %d\n", v, u); if ((ds[v] & 1) == (ds[u] & 1)) { ++bad; cnt[v]++; cnt[u]--; } else { cnt[v]--; cnt[u]++; } } else if (!ds[u]) { ds[u] = ds[v] + 1; tr[v].emplace_back(u); // printf("tree edge %d -> %d\n", v, u); dfs1(u, v); } } } void dfs2(int v) { for (int u : tr[v]) { dfs2(u); cnt[v] += cnt[u]; } } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; ++i) { int v, u; scanf("%d %d", &v, &u); g[v].emplace_back(u); g[u].emplace_back(v); } for (int i = 1; i <= n; ++i) { if (!ds[i]) { ds[i] = 1; dfs1(i, -1); } } for (int i = 1; i <= n; ++i) { if (ds[i] == 1) { dfs2(i); } } int ans = 0; for (int i = 1; i <= n; ++i) { if (ds[i] > 1 && cnt[i] == bad) { ++ans; } } // printf("%d\n", bad); ans += (bad == 1); printf("%d\n", ans); }

Compilation message (stderr)

voltage.cpp: In function 'int main()':
voltage.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &n, &m);
    ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:47:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &v, &u);
       ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...