| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 210850 | Lawliet | Dynamic Diameter (CEOI19_diameter) | C++17 | 5025 ms | 12536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int MAXN = 100010;
int n, q;
int weight[MAXN];
lli maxW;
lli lastAns;
lli prof[MAXN];
vector< int > adj[MAXN];
vector< int > indEdge[MAXN];
void DFS(int cur, int p)
{
for(int i = 0 ; i < adj[cur].size() ; i++)
{
int viz = adj[cur][i];
int ind = indEdge[cur][i];
if( viz == p ) continue;
prof[viz] = prof[cur] + weight[ind];
DFS( viz , cur );
}
}
int getFarthest()
{
int opt = 1;
for(int i = 2 ; i <= n ; i++)
if( prof[opt] < prof[i] ) opt = i;
return opt;
}
lli diameter()
{
prof[1] = 0;
DFS( 1 , 1 );
int cur = getFarthest();
prof[cur] = 0;
DFS( cur , cur );
return prof[ getFarthest() ];
}
int main()
{
scanf("%d %d %lld",&n,&q,&maxW);
for(int i = 1 ; i < n ; i++)
{
int U, V, W;
scanf("%d %d %d",&U,&V,&W);
adj[U].push_back( V );
adj[V].push_back( U );
indEdge[U].push_back( i );
indEdge[V].push_back( i );
weight[i] = W;
}
for(int i = 1 ; i <= q ; i++)
{
lli d, e;
scanf("%lld %lld",&d,&e);
d = ( d + lastAns )%( n - 1 ) + 1;
e = ( e + lastAns )%maxW;
weight[d] = e;
lastAns = diameter();
printf("%lld\n",lastAns);
}
}
컴파일 시 표준 에러 (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... | ||||
