이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
#define printl(args...) printf(args)
#else
#define printl(args...) 0
#endif
int n,q;
int timer;
ll w[100005];
pair<int,int>edge[100005];
vector<pair<int,int>>g[100005];
bool vis[100005];
int sz[100005];
int par[100005];
int depth[100005];
void build_sz(int v,int p){
sz[v]=1;
for(auto &to:g[v])if((to.fr^p)&&(!vis[to.fr])){
build_sz(to.fr,v);
sz[v]+=sz[to.fr];
}
}
int centroid(int v,int p,int sz){
bool can;
while(true){
can=true;
for(auto &to:g[v])if((to.fr^p)&&(!vis[to.fr])){
if(::sz[to.fr]>sz){
can=false;
p=v;
v=to.fr;
break;
}
}
if(can)return v;
}
}
void build(int v,int p,int dep){
build_sz(v,0);
v=centroid(v,0,sz[v]>>1);
par[v]=p;
depth[v]=dep;
vis[v]=true;
for(auto &to:g[v])if(!vis[to.fr])build(to.fr,v,dep+1);
}
ll ans;
struct SegmentTree{
vector<ll>vec;
int n;
SegmentTree(int _n){
n=_n;
vec.assign(n<<2|3,0ll);
}
};
ll alls[100005];
ll go(int v,int p,int &pivot,ll depth){
ll mx=depth;
if(!p){
ll m1=0,m2=0;
for(auto &to:g[v])if((to.fr^p)&&::depth[to.fr]>pivot){
ll cur=go(to.fr,v,pivot,depth+w[to.sc]);
umax(mx,cur);
if(cur>m1){
m2=m1;
m1=cur;
}else if(cur>m2)m2=cur;
}
mx=m1+m2;
}else for(auto &to:g[v])if((to.fr^p)&&::depth[to.fr]>pivot)umax(mx,go(to.fr,v,pivot,depth+w[to.sc]));
return mx;
}
int main(){
scanf("%d%d%lld",&n,&q,&w[0]);
for(int i=1;i^n;i++){
scanf("%d%d%lld",&edge[i].fr,&edge[i].sc,&w[i]);
g[edge[i].fr].emplace_back(edge[i].sc,i);
g[edge[i].sc].emplace_back(edge[i].fr,i);
}
build(1,0,0);
for(int i=1;i^n;i++)if(depth[edge[i].fr]>depth[edge[i].sc])swap(edge[i].fr,edge[i].sc);
for(int i=1;i<=n;i++)alls[i]=go(i,0,depth[i],0);
while(q--){
ll x;
ll y;
scanf("%lld%lld",&x,&y);
x=(x+ans)%(n-1)+1;
y=(y+ans)%w[0];
//Episode 1-> Think hard
w[x]=y;
x=edge[x].fr;
while(x){
alls[x]=go(x,0,depth[x],0);
x=par[x];
}
ans=0;
for(int i=1;i<=n;i++)umax(ans,alls[i]);
printf("%lld\n",ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
diameter.cpp: In function 'int main()':
diameter.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d%d%lld",&n,&q,&w[0]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | scanf("%d%d%lld",&edge[i].fr,&edge[i].sc,&w[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | 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... |