Submission #578793

#TimeUsernameProblemLanguageResultExecution timeMemory
578793talant117408Dynamic Diameter (CEOI19_diameter)C++17
24 / 100
2447 ms21308 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define long unsigned long #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' const int N = 1e5+7; set <pair <int, ll>> graph[N]; vector <pair <pii, ll>> edges; ll df, vf; void find_furthest(int v, int p, ll dist = 0) { if (dist > df) { df = dist; vf = v; } for (auto to : graph[v]) { if (to.first == p) continue; find_furthest(to.first, v, dist+to.second); } } void solve() { int n, q; ll w; cin >> n >> q >> w; for (int i = 0; i < n-1; i++) { int a, b; ll c; cin >> a >> b >> c; edges.pb(mp(mp(a, b), c)); graph[a].insert(mp(b, c)); graph[b].insert(mp(a, c)); } if (n <= 5000) { ll last = 0; while (q--) { ll d, e; cin >> d >> e; d = (d + last) % (n - 1); e = (e + last) % w; auto a = edges[d].first.first, b = edges[d].first.second; auto &c = edges[d].second; graph[a].erase(graph[a].find(mp(b, c))); graph[b].erase(graph[b].find(mp(a, c))); c = e; graph[a].insert(mp(b, c)); graph[b].insert(mp(a, c)); df = vf = 0; find_furthest(1, 1); df = 0; find_furthest(vf, vf); cout << df << endl; last = df; } } } int main() { do_not_disturb int t = 1; //~ cin >> t; while (t--) { solve(); } return 0; } /* */
#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...