Submission #658514

#TimeUsernameProblemLanguageResultExecution timeMemory
658514mychecksedadDynamic Diameter (CEOI19_diameter)C++17
24 / 100
5053 ms45792 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; #define MOD1 (1000000000+7) #define MOD (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20; int n, q; ll w, dp[N]; vector<int> g[N]; vector<pair<int, ll>> edges(N); ll dfs(int v, int p){ pair<ll, ll> best = {0, 0}; dp[v] = 0; ll d = 0; for(int E: g[v]){ auto e = edges[E]; int u = e.first; if(u == p) continue; d = max(d, dfs(u, v)); dp[v] = max(dp[v], dp[u] + e.second); if(best.first < dp[u] + e.second){ swap(best.first, best.second); best.first = dp[u] + e.second; }else if(best.second < dp[u] + e.second){ best.second = dp[u] + e.second; } } return max(d, best.first + best.second); } void solve(){ cin >> n >> q >> w; for(int i = 0; i < n - 1; ++i){ int u, v; ll x; cin >> u >> v >> x; g[u].pb(2*i); g[v].pb(2*i+1); edges[i*2] = {v, x}; edges[i*2+1] = {u, x}; } ll last = 0; for(;q--;){ ll d, x; cin >> d >> x; d = (d + last) % (n-1); x = (x + last) % w; edges[2*d].second = edges[2*d+1].second = x; last = dfs(1, 0); cout << last << '\n'; } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

diameter.cpp: In function 'int main()':
diameter.cpp:72:16: warning: unused variable 'aa' [-Wunused-variable]
   72 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...