結果
| 問題 |
No.2214 Products on Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-16 21:42:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 3,000 ms |
| コード長 | 2,792 bytes |
| コンパイル時間 | 2,376 ms |
| コンパイル使用メモリ | 195,260 KB |
| 実行使用メモリ | 26,456 KB |
| 最終ジャッジ日時 | 2025-10-16 21:42:31 |
| 合計ジャッジ時間 | 5,315 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
//饺子皮是圆皮
#include<bits/stdc++.h>
using namespace std;
namespace fast_IO{
#define FASTIO
#define IOSIZE 1000000
char ibuf[IOSIZE],obuf[IOSIZE];char*p1=ibuf,*p2=ibuf,*p3=obuf;
#ifdef ONLINE_JUDGE
#define getchar()((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x)((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#endif
#define isdigit(ch)(ch>47&&ch<58)
#define isspace(ch)(ch<33)
template<typename T>inline T read(){T s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)and(ch!=EOF))if(ch=='-')w=-1;if(ch==EOF)return false;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*w;}template<typename T>inline bool read(T&s){s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)and(ch!=EOF))if(ch=='-')w=-1;if(ch==EOF)return false;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*=w,true;}inline bool read(char&s){while(s=getchar(),isspace(s));return true;}inline bool read(char*s){char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return false;while(!isspace(ch))*s++=ch,ch=getchar();*s='\000';return true;}template<typename T>inline void print(T x){if(x<0)putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+48);}inline void print(char x){putchar(x);}inline void print(char*x){while(*x)putchar(*x++);}inline void print(const char*x){for(int i=0;x[i];i++)putchar(x[i]);}
#ifdef _GLIBCXX_STRING
inline bool read(std::string&s){s="";char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return false;while(!isspace(ch))s+=ch,ch=getchar();return true;}inline void print(std::string x){for(int i=0,n=x.size();i<n;i++)putchar(x[i]);}
#endif
template<typename T,typename...T1>inline int read(T&a,T1&...other){return read(a)+read(other...);}template<typename T,typename...T1>inline void print(T a,T1...other){print(a);print(other...);}struct Fast_IO{~Fast_IO(){fwrite(obuf,p3-obuf,1,stdout);}}io;template<typename T>Fast_IO&operator>>(Fast_IO&io,T&b){return read(b),io;}template<typename T>Fast_IO&operator<<(Fast_IO&io,T b){return print(b),io;}
}
#define cin fast_IO::io
#define cout fast_IO::io
#define endl '\n'
//
const int maxn=2e5+10;
const int mod=998244353;
int n;
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
struct Edge{int v,next;}edge[maxn<<1];
int head[maxn],tot;
void add_edge(int u,int v){
edge[++tot]={v,head[u]};
head[u]=tot;
}
int f[maxn][2];
void dfs(int u,int fa){
f[u][0]=1,f[u][1]=1;
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].v;
if(v==fa)continue ;
dfs(v,u);
f[u][1]=add(1ll*f[u][1]*add(f[v][0],f[v][1])%mod,1ll*f[u][0]*f[v][1]%mod);
f[u][0]=1ll*f[u][0]*add(f[v][0],f[v][1])%mod;
}
}
int main(){
cin>>n;
for(int i=1,u,v;i<n;i++)cin>>u>>v,add_edge(u,v),add_edge(v,u);
dfs(1,0);
cout<<f[1][1]<<'\n';
return 0;
}