이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,i,j,k,l,r,x,y,z,w,s,t,h[1100000],ans,qu,len[1100000],dia[1100000],dep[1100000],par[1100000];
vector<pair<ll,ll>> v[1100000];
pair<ll,ll> pq;
multiset<ll> st;
pair<ll,pair<ll,ll>> p[1100000],q[1100000];
ll f(ll x,ll y)
{
    dep[x]=dep[y]+1;
    par[x]=y;
    ll i,s=0,z,t=0;
    for(i=0;i<h[x];i++)
    {
        if(v[x][i].first==y)
            continue;
        z=f(v[x][i].first,x)+v[x][i].second;
        s+=z;
        t=max(t,z);
    }
    dia[x]=s;
    st.insert(-dia[x]);
    len[x]=t;
    return t;
}
void g(ll x,ll y)
{
    if(x==0)
        return;
    ll i,s=0,z,t=0;
    for(i=0;i<h[x];i++)
    {
        if(v[x][i].first==y)
            continue;
        z=len[v[x][i].first]+v[x][i].second;
        s+=z;
        t=max(t,z);
    }
    st.erase(st.find(-dia[x]));
    dia[x]=s;
    st.insert(-dia[x]);
    len[x]=t;
    g(par[x],par[y]);
    return;
}
int main()
{
    scanf("%lld %lld %lld",&n,&qu,&w);
    for(i=1;i<n;i++)
    {
        scanf("%lld %lld %lld",&x,&y,&z);
        p[i]={x,{h[x],z}};
        q[i]={y,{h[y],z}};
        v[x].push_back({y,z});
        v[y].push_back({x,z});
        h[x]++;
        h[y]++;
    }
    f(1,0);
    for(i=1;i<=qu;i++)
    {
        scanf("%lld %lld",&x,&y);
        x=(x+ans)%(n-1);
        y=(y+ans)%w;
        x++;
        v[p[x].first][p[x].second.first].second=y;
        p[x].second.second=y;
         v[q[x].first][q[x].second.first].second=y;
        q[x].second.second=y;
        y=p[x].first;
        x=q[x].first;
        if(dep[x]<dep[y])
            swap(x,y);
        g(x,y);
        ans=(*st.begin());
        ans*=-1;
        printf("%lld\n",ans);
    }
}
컴파일 시 표준 에러 (stderr) 메시지
diameter.cpp: In function 'int main()':
diameter.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%lld %lld %lld",&n,&qu,&w);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld %lld %lld",&x,&y,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         scanf("%lld %lld",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~| # | 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... |