标签:read == problem line void inline 传送门 表示 putchar
#include <bits/stdc++.h>
#define getchar nc
#define N 100005
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register int x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[20];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
inline int Min(register int a,register int b)
{
return a<b?a:b;
}
struct node{
int to,next;
}e[N<<1];
int head[N],cnt=0;
inline void add(register int u,register int v)
{
e[++cnt]=(node){v,head[u]};
head[u]=cnt;
}
int n,f[N][2];
inline void dfs(register int u,register int fa)
{
f[u][1]=1;
f[u][0]=0;
for(register int i=head[u];i;i=e[i].next)
{
int v=e[i].to;
if(v==fa)
continue;
dfs(v,u);
f[u][1]+=Min(f[v][0],f[v][1]);
f[u][0]+=f[v][1];
}
}
int main()
{
n=read();
for(register int i=1;i<n;++i)
{
int u=read(),v=read();
add(u,v),add(v,u);
}
dfs(1,0);
write(Min(f[1][0],f[1][1]));
return 0;
}
【题解】Luogu SP1435 PT07X - Vertex Cover
标签:read == problem line void inline 传送门 表示 putchar
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/10329700.html