이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |