Submission #469948

#TimeUsernameProblemLanguageResultExecution timeMemory
4699481bin산만한 고양이 (KOI17_cat)C++14
100 / 100
371 ms60520 KiB
#include <bits/stdc++.h> #include <cassert> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 3e5 + 5; ll n, m, a, b, dfsn[NMAX], cnt[NMAX], x[NMAX], y[NMAX], t, ans, sum; vector<int> adj[NMAX]; void dfs(int now, int bef) { dfsn[now] = ++t; int f = 1; for (int nx : adj[now]) { if (nx == bef) continue; if (!dfsn[nx]) { ll c = cnt[now]; dfs(nx, now); cnt[now] += cnt[nx]; if (cnt[now] - c > 1) f = 0; x[now] += x[nx]; y[now] += y[nx]; } else if (dfsn[nx] < dfsn[now]) x[now]++, cnt[now]++, cnt[nx]--; else y[bef]++; } if (!y[now] && !(sum - x[now]) && f) ans += now; return; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; sum = m - (n - 1); assert(sum > 0); while (m--) { cin >> a >> b; adj[a].emplace_back(b); adj[b].emplace_back(a); } dfs(1, 0); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...