제출 #1040549

#제출 시각아이디문제언어결과실행 시간메모리
1040549antonDynamic Diameter (CEOI19_diameter)C++17
24 / 100
5063 ms27692 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> int N, Q, W; const int MAX_N = 1e5; vector<unordered_map<int, int>> adj; pii get_furthest(int u, int a){ pii res ={0, u}; for(auto e: adj[u]){ if(e.first!=a){ pii de = get_furthest(e.first, u); de.first += e.second; if(de.first>res.first){ res = de; } } } return res; } signed main(){ cin>>N>>Q>>W; adj.resize(N); vector<pii> edges; for(int i = 0; i<N-1; i++){ int a, b, c; cin>>a>>b>>c; a--;b--; adj[a][b] = c; adj[b][a] = c; edges.push_back({a, b}); } int last= 0; for(int i = 0; i<Q; i++){ int d, e; cin>>d>>e; d = (d+last)%(N-1); e = (e +last)%W; int a = edges[d].first; int b= edges[d].second; adj[a][b] = e; adj[b][a] =e; int u = get_furthest(0, -1).second; last = get_furthest(u, -1).first; cout<<last<<endl; } }
#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...