fork download
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<vector>
  5. #define rep(i,a,b) for(int i=a;i<=b;i++)
  6. using namespace std;
  7. typedef long long ll;
  8. const ll mod = 1000000007;
  9. const int maxn=2e5;
  10. int q,n=1,v[maxn+1];
  11. vector<int> g[maxn+1];
  12. ll pv[maxn+1];
  13. void dfs(int u)
  14. {
  15. for(int v:g[u])dfs(v);
  16. int tt=1;
  17. pv[u]=v[u];
  18. for(int v:g[u]){pv[u]+=pv[v];tt++;}
  19. pv[u]%=mod;
  20. pv[u]*=tt;
  21. pv[u]%=mod;
  22. }
  23. int main()
  24. {
  25. scanf("%d %d",&v[n],&q);
  26. bool change = true;
  27. rep(i,1,q)
  28. {
  29. int t;
  30. scanf("%d ",&t);
  31. if(t == 1) {
  32. int p;
  33. ++n;
  34. scanf("%d %d\n",&p,&v[n]);
  35. g[p].push_back(n);
  36. change = true;
  37. }else {
  38. int x;
  39. scanf("%d\n",&x);
  40. if(change) {
  41. dfs(1);
  42. }
  43. printf("%lld\n",pv[x]);
  44. change = false;
  45. }
  46. }
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 8140KB
stdin
Standard input is empty
stdout
Standard output is empty