# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
373733 | LucaDantas | Dynamic Diameter (CEOI19_diameter) | C++17 | 2143 ms | 17268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 2e5+10;
vector<pair<int,int>> g[maxn];
int n, q;
long long dist[maxn], cost[maxn], w;
void dfs(int u, int p) {
for(auto [v, id] : g[u]) {
if(v != p) {
dist[v] = dist[u] + cost[id];
dfs(v, u);
}
}
}
void brute() {
int last = 0;
while(q--) {
int d, e; scanf("%d %d", &d, &e);
d = (d + last) % (n - 1);
e = (e + last) % w;
cost[d] = e;
dist[1] = 0;
dfs(1, 0);
int x = max_element(dist+1, dist+n+1) - dist;
dist[x] = 0;
dfs(x, 0);
printf("%lld\n", *max_element(dist+1, dist+n+1));
last = *max_element(dist+1, dist+n+1);
}
exit(0);
}
void bst() {
multiset<long long, greater<long long>> st;
for(int i = 0; i < n-1; i++)
st.insert(cost[i]);
int last = 0;
while(q--) {
int d, e; scanf("%d %d", &d, &e);
d = (int)((d + last) % (n - 1));
e = (int)((e + last) % w);
st.erase(st.find(cost[d]));
cost[d] = e;
st.insert(e);
last = (int)(*st.begin() + (n>2?*next(st.begin()):0));
printf("%d\n", last);
}
exit(0);
}
int main() {
scanf("%d %d %lld", &n, &q, &w);
// printf("%d %d %lld\n", n, q, w);
if(w > 10000) assert(0);
for(int i = 0; i < n-1; i++) {
int a, b; long long c; scanf("%d %d %lld", &a, &b, &c);
// printf("%d %d %lld\n", a, b, c);
g[a].push_back({b, i});
g[b].push_back({a, i});
cost[i] = c;
}
if((int)g[1].size() == n-1) bst();
if(n <= 5000) brute();
}
컴파일 시 표준 에러 (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... |