제출 #488776

#제출 시각아이디문제언어결과실행 시간메모리
488776cfalasDynamic Diameter (CEOI19_diameter)C++14
7 / 100
549 ms21364 KiB
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) int t, n; vi a, b; vector<vii> adj; ii f; void dfs(int s, int p=-1, ll d=0){ if(d>f.F) f = max(f, {d, s}); FOA(v, adj[s]){ if(v.F!=p) dfs(v.F, s, d+v.S); } } int main(){ int q; ll w; cin>>n>>q>>w; adj.assign(n+1, vii()); vector<pair<ii,ii> > edg(n-1); set<ii> ws; vi wu(n); FOR(i,n-1){ ll a, b, c; cin>>a>>b>>c; ws.insert({-c, i}); wu[i] = c; edg[i] = {{a, adj[a].size()}, {b, adj[b].size()}}; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } ll last=0; while(q--){ ll a, b; cin>>a>>b; a= (a + last) % (n-1); b = (b+last) % w; adj[edg[a].F.F][edg[a].F.S].S = b; adj[edg[a].S.F][edg[a].S.S].S = b; f = {0,1}; //dfs(1); //dfs(f.S); ws.erase({-wu[a], a}); ws.insert({-b, a}); wu[a] = b; //last = f.F; if(n==2) last = -(*ws.begin()).F; else last = -(*ws.begin()).F - (*(++ws.begin())).F; 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...