이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
for (int nx : adj[now]) {
if (nx == bef) continue;
if (!dfsn[nx]) {
dfs(nx, now);
cnt[now] += cnt[nx]; x[now] += x[nx]; y[now] += y[nx];
}
else if (dfsn[nx] < dfsn[now]) {
cnt[bef]++, cnt[nx]--;
x[now]++;
}
else y[bef]++;
}
if (!y[now] && cnt[now] <= 1 && !(sum - x[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... |