1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; typedef long long LL; namespace FastIO { const int L=1<<15; char buf[L],*S,*T; char getchar() { if(S==T){T=(S=buf)+fread(buf,1,L,stdin);if(S==T)return EOF;} return *S++; } LL Get_Int(){ LL res=0,bj=1;char c=getchar(); while(!isdigit(c)){if(c=='-')bj=-1;c=getchar();} while(isdigit(c)){res=res*10+c-'0';c=getchar();} return res*bj; } } using FastIO::Get_Int; const int maxn=2000005; const LL mod=32416190071; int n,vst[maxn],ans=0; LL f[maxn]; struct Edge { int from,to,dist; }; vector<Edge>edges[maxn]; void AddEdge(int x,int y,int v) { edges[x].push_back((Edge) { x,y,v }); } void Dfs(int Now) { for(auto& e:edges[Now]) { int Next=e.to; Dfs(Next); f[Now]=(f[Now]+f[Next]*e.dist)%mod; } } int main() { int size=100<<20; __asm__ ("movq %0,%%rsp\n"::"r"((char*)malloc(size)+size)); n=Get_Int(); for(int i=1; i<n; i++) { int x=Get_Int(),y=Get_Int(),v=Get_Int(); vst[y]=1; AddEdge(x,y,v); } int root; for(int i=1; i<=n; i++) { f[i]=Get_Int()%mod; if(!edges[i].size())ans++; if(!vst[i])root=i; } Dfs(root); printf("%d\n%lld\n",ans,f[root]); exit(0); }
|