社区讨论

我不开02过了,开了02RE+TLE

P2796Facer的程序参与者 6已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@lo3ai7nu
此快照首次捕获于
2023/10/24 03:27
2 年前
此快照最后确认于
2023/10/24 03:27
2 年前
查看原帖
麻烦帮忙看下哪的问题,谢谢
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
//const int SIZE=1<<13;
//static char buf[SIZE],*be=buf,*en=buf,obuf[SIZE],*p3=obuf;
//#define getchar() be==en&&(en=(be=buf)+fread(buf,1,SIZE,stdin),be==en)?EOF:*be++;
inline int read(){
     int x=0,f=1;char ch=getchar();
     while(!isdigit(ch))f=ch!='-',ch=getchar();
     while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
     return f?x:-x;
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
	return;
}
const int N=1e5+10,mod=1000000007;
int head[N],dp[N],cnt,ans=0;
struct node{
	int to,next;
}e[N*2];
inline int add(int x,int y){
	e[++cnt].to=y,e[cnt].next=head[x],head[x]=cnt;
}
void dfs(int u,int fa){
	dp[u]=1;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		dfs(v,u);
		dp[u]=(dp[v]+1)*dp[u]%mod;	
    }
    ans=(ans+dp[u])%mod;
}
signed main(){
	int n;
	n=read();
	for(int i=1;i<n;i++){
		int u,v;
		u=read();v=read();
		add(u,v);add(v,u);
	}
	dfs(1,0);
	write(ans);
 	return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...