思路:
我们发现,它一定是一个基环树森林。
所以我们就每个基环树进行DP然后加起来就行了
c o d e code code
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const ll MAXN = 1e6 + 10;
ll n, huan[MAXN], cnt, f[MAXN][2], dp[MAXN][2][2];
ll a[MAXN], head[MAXN], tot;
ll stack[MAXN], top, ans;
struct node {
ll to, next;
}b[MAXN << 1];
bool v[MAXN], bz[MAXN], v1[MAXN];
void add(ll x, ll y) {
b[++ tot] = (node) {
y, head[x] };
head[x] = tot;
}
void dfs(ll x, ll fa) {
if(cnt) return ;
v[x] = 1;
stack[++ top] = x;
int flag = 0;
for(ll i = head[x]; i; i = b[i].next) {
ll y = b[i].to;
if(cnt) return ;
if(y == fa) {
flag ++;
if(flag == 2) {
cnt = 2, huan[1] = fa, huan[