caotianhao @ 2023-07-18 15:24:03
提交记录
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int n,cnt,head[N],dp[N][2],son[N],vis[N];
struct tree{
int v,nex;
}e[N*2];
void add(int u,int v){
e[++cnt].v=v;
e[cnt].nex=head[u];
head[u]=cnt;
}
int dfs(int u){
vis[u]=1;
dp[u][1]++;
for(int i=head[u];i;i=e[i].nex){
if(!vis[e[i].v]){
dfs(e[i].v);
dp[u][0]+=dp[e[i].v][1];
dp[u][1]+=min(dp[e[i].v][0],dp[e[i].v][1]);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int u,k;
cin>>u>>k;
for(int j=1;j<=k;j++){
int v;
cin>>v;
add(u,v);
add(v,u);
}
}
dfs(1);
cout<<min(dp[1][0],dp[1][1]);
return 0;
}
by Happy_Doggie @ 2023-07-18 15:25:32
by caotianhao @ 2023-07-18 15:26:30
@weee ???
by caotianhao @ 2023-07-18 15:26:55
我是TLE
by Happy_Doggie @ 2023-07-18 15:28:02
哦
by lcy_123 @ 2023-07-18 16:08:42
开O2
by UncleSam_Died @ 2023-07-18 16:20:49
@caotianhao 其实,你并没有TLE,有可能只是当时你谷日爆了,你的代码我的AC
by UncleSam_Died @ 2023-07-18 16:21:05
@caotianhao 千万不要关注我
by caotianhao @ 2023-07-18 16:40:28
关于我把int dfs()改成
void dfs()后过了这件事