P1352 没有上司的舞会 https://www.luogu.com.cn/problem/P1352
#include
using namespace std;
const int maxn=1e6+5;
struct node
{
int to,nxt;
}e[maxn];
int n,r[maxn],f[maxn][4],head[maxn],cnt,in[maxn];
void add(int from,int to)
{
e[++cnt].to=to;
e[cnt].nxt=head[from];
head[from]=cnt;
}
void dfs(int u)
{
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].to;
dfs(v);
f[u][0]+=max(f[v][0],f[v][1]);
f[u][1]+=f[v][0];
}
f[u][1]+=r[u];
}
int main()
{
scanf("%d",&n);
for(int i=1;i
关注
打赏