This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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], y[NMAX], t, ans, sum;
vector<int> adj[NMAX];
void dfs(int now, int bef) {
dfsn[now] = ++t;
ll x = 0;
for (int nx : adj[now]) {
if (nx == bef) continue;
if (!dfsn[nx]) {
dfs(nx, now);
cnt[now] += cnt[nx]; y[now] += y[nx];
}
else if (dfsn[nx] < dfsn[now]) x++, cnt[bef]++;
else x++, cnt[now]--, y[bef]++;
}
if (!y[now] && cnt[now] <= 1 && !(sum - x - y[now] - cnt[now])) ans += now;
return;
}
int main(void) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
sum = m - (n - 1);
while (m--) {
cin >> a >> b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
dfs(1, 0);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |