fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using namespace std::chrono;
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
  7. #define pb push_back
  8. #define eb emplace_back
  9. #define mp make_pair
  10. #define ff first
  11. #define ss second
  12. #define vt vector
  13. #define vll vt<ll>
  14. #define pll pair<ll,ll>
  15. #define vpll vt<pll>
  16. #define vvll vt<vll>
  17. #define all(v) v.begin(),v.end()
  18. #define FOR(i,n) for(ll i=0;i<n;i++)
  19. #define ffo(i,a,b) for(ll i=a;i<=b;i++)
  20. #define rfo(i,a,b) for(ll i=a;i>=b;i--)
  21. #define space cout<<"\n\n";
  22. #define endl "\n"
  23. #define pqmx priority_queue<ll>
  24. #define pqmn priority_queue<ll,vll,greater<ll>>
  25. #define fps(x,y) fixed<<setprecision(y)<<x
  26. #define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
  27. #define set_ar(arr,v) memset(arr,v,sizeof(arr))
  28. #define go_t int testcases; cin>>testcases; ffo(caseno,1,testcases)
  29.  
  30. #define ctime auto start = high_resolution_clock::now()
  31. #define etime auto stop = high_resolution_clock::now()
  32. #define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
  33.  
  34. const ll mod = 1e9 + 7;
  35. const ll N = 6e4 + 6;
  36. const ll maxN = 3e5 + 5;
  37. const ll MAX_SIZE = 2e6 + 6;
  38. const ll INF = 0x3f3f3f3f3f3f3f3fll;
  39. const double PI = 3.14159265359;
  40.  
  41. int dx[4] = { -1, 0, 1, 0};
  42. int dy[4] = {0, 1, 0, -1};
  43. // up, right, down, left
  44.  
  45. ll powerM(ll x, ll y, ll M = mod) { // default argument
  46. ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
  47. }
  48.  
  49. ll power(ll x, ll y) {
  50. ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
  51. }
  52.  
  53. // WHY THE HELL IS IT NOT WORKING USING FENWICK TREE
  54.  
  55. ll timer = 1, n, q;
  56. ll in[maxN];
  57. ll out[maxN];
  58. vll g[maxN];
  59. double bit[2 * maxN]; // this is 1 indexed
  60.  
  61. void dfs(ll node, ll p) {
  62. in[node] = timer;
  63. for (auto& u : g[node]) {
  64. if (u == p)
  65. continue;
  66. ++timer;
  67. dfs(u, node);
  68. }
  69. out[node] = timer;
  70. }
  71.  
  72. void update(ll idx, double val) {
  73. double prev = bit[idx];
  74. double change = val - prev;
  75. while (idx <= n) {
  76. bit[idx] += change;
  77. idx += (idx & (-idx));
  78. }
  79. }
  80.  
  81. double sum(ll idx) {
  82. double s = 0.0d;
  83. while (idx > 0) {
  84. s += bit[idx];
  85. idx -= (idx & (-idx));
  86. }
  87. return s;
  88. }
  89.  
  90. int main()
  91. {
  92. #ifndef ONLINE_JUDGE
  93. freopen("in4.txt", "r", stdin);
  94. freopen("out1.txt", "w", stdout);
  95. #endif
  96. FIO
  97. cin >> n;
  98. FOR(i, n - 1) {
  99. ll u, v;
  100. cin >> u >> v;
  101. --u, --v;
  102. g[u].pb(v);
  103. g[v].pb(u);
  104. }
  105. dfs(0, -1);
  106. cout << fixed << setprecision(12);
  107. cin >> q;
  108. while (q--) {
  109. ll t, x, y;
  110. cin >> t >> x >> y;
  111. if (t == 1) {
  112. --x;
  113. update(in[x], log2(y * 1.0d));
  114. continue;
  115. }
  116. --x, --y;
  117. double s1 = sum(out[x]) - sum(in[x] - 1);
  118. double s2 = sum(out[y]) - sum(in[y] - 1);
  119. double as = 1000000000.0d;
  120. if (s1 - s2 >= log2(1000000000.0d)) {
  121. cout << as << endl;
  122. }
  123. else {
  124. cout << pow(2.0, s1 - s2) << endl;
  125. }
  126. }
  127. return 0;
  128. }
  129.  
Success #stdin #stdout 0s 10900KB
stdin
5
4 2
1 4
5 4
3 4
5
2 5 2
1 5 4
1 5 5
1 5 4
2 5 4
stdout
1.000000000000
1.000000000000