# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
446253 | qwerasdfzxcl | Dynamic Diameter (CEOI19_diameter) | C++14 | 5065 ms | 22852 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Edge{
int s, e, x;
Edge(){}
Edge(int _s, int _e, int _x): s(_s), e(_e), x(_x){}
}e[100100];
set<pair<int, int>> adj[100100];
int dist[100100];
void dfs(int s, int pa = -1){
for (auto &v:adj[s]) if (v.first!=pa){
dist[v.first] = dist[s]+v.second;
dfs(v.first, s);
}
}
signed main(){
int n, q, w;
scanf("%lld %lld %lld", &n, &q, &w);
for (int i=0;i<n-1;i++){
scanf("%lld %lld %lld", &e[i].s, &e[i].e, &e[i].x);
adj[e[i].s].insert(make_pair(e[i].e, e[i].x));
adj[e[i].e].insert(make_pair(e[i].s, e[i].x));
}
int last = 0;
while(q--){
int x, y;
scanf("%lld %lld", &x, &y);
x = (x+last)%(n-1);
y = (y+last)%w;
adj[e[x].s].erase(adj[e[x].s].find(make_pair(e[x].e, e[x].x)));
adj[e[x].e].erase(adj[e[x].e].find(make_pair(e[x].s, e[x].x)));
adj[e[x].s].insert(make_pair(e[x].e, y));
adj[e[x].e].insert(make_pair(e[x].s, y));
e[x].x = y;
dist[1] = 0;
dfs(1);
int idx = max_element(dist+1, dist+n+1) - dist;
dist[idx] = 0;
dfs(idx);
last = *max_element(dist+1, dist+n+1);
printf("%lld\n", last);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |