#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;
vector<pair<ll,ll>> v[1100000];
pair<ll,ll> pq;
pair<ll,pair<ll,ll>> p[1100000],q[1100000];
pair<ll,ll> f(ll x,ll y)
{
ll i;
pair<ll,ll> p={x,0},q;
for(i=0;i<h[x];i++)
{
if(v[x][i].first==y)
continue;
q=f(v[x][i].first,x);
if(q.second+v[x][i].second>p.second)
{
p={q.first,q.second+v[x][i].second};
}
}
return p;
}
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]++;
}
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;
pq=f(1,0);
ans=f(pq.first,0).second;
printf("%lld\n",ans);
}
}
Compilation message
diameter.cpp: In function 'int main()':
diameter.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%lld %lld %lld",&n,&qu,&w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%lld %lld %lld",&x,&y,&z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%lld %lld",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
29016 KB |
Output is correct |
2 |
Correct |
8 ms |
29020 KB |
Output is correct |
3 |
Correct |
8 ms |
29016 KB |
Output is correct |
4 |
Correct |
8 ms |
29020 KB |
Output is correct |
5 |
Correct |
8 ms |
29136 KB |
Output is correct |
6 |
Correct |
8 ms |
29016 KB |
Output is correct |
7 |
Correct |
8 ms |
29184 KB |
Output is correct |
8 |
Correct |
8 ms |
29020 KB |
Output is correct |
9 |
Correct |
9 ms |
29172 KB |
Output is correct |
10 |
Correct |
9 ms |
29032 KB |
Output is correct |
11 |
Correct |
9 ms |
29020 KB |
Output is correct |
12 |
Correct |
10 ms |
29020 KB |
Output is correct |
13 |
Correct |
9 ms |
29172 KB |
Output is correct |
14 |
Correct |
9 ms |
29016 KB |
Output is correct |
15 |
Correct |
8 ms |
29020 KB |
Output is correct |
16 |
Correct |
9 ms |
29104 KB |
Output is correct |
17 |
Correct |
9 ms |
29016 KB |
Output is correct |
18 |
Correct |
8 ms |
29020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
29016 KB |
Output is correct |
2 |
Correct |
8 ms |
29020 KB |
Output is correct |
3 |
Correct |
8 ms |
29016 KB |
Output is correct |
4 |
Correct |
8 ms |
29020 KB |
Output is correct |
5 |
Correct |
8 ms |
29136 KB |
Output is correct |
6 |
Correct |
8 ms |
29016 KB |
Output is correct |
7 |
Correct |
8 ms |
29184 KB |
Output is correct |
8 |
Correct |
8 ms |
29020 KB |
Output is correct |
9 |
Correct |
9 ms |
29172 KB |
Output is correct |
10 |
Correct |
9 ms |
29032 KB |
Output is correct |
11 |
Correct |
9 ms |
29020 KB |
Output is correct |
12 |
Correct |
10 ms |
29020 KB |
Output is correct |
13 |
Correct |
9 ms |
29172 KB |
Output is correct |
14 |
Correct |
9 ms |
29016 KB |
Output is correct |
15 |
Correct |
8 ms |
29020 KB |
Output is correct |
16 |
Correct |
9 ms |
29104 KB |
Output is correct |
17 |
Correct |
9 ms |
29016 KB |
Output is correct |
18 |
Correct |
8 ms |
29020 KB |
Output is correct |
19 |
Correct |
70 ms |
29272 KB |
Output is correct |
20 |
Correct |
72 ms |
29284 KB |
Output is correct |
21 |
Correct |
79 ms |
29320 KB |
Output is correct |
22 |
Correct |
114 ms |
29384 KB |
Output is correct |
23 |
Correct |
651 ms |
29644 KB |
Output is correct |
24 |
Correct |
791 ms |
29776 KB |
Output is correct |
25 |
Correct |
890 ms |
29728 KB |
Output is correct |
26 |
Correct |
1165 ms |
30288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29272 KB |
Output is correct |
2 |
Correct |
9 ms |
29020 KB |
Output is correct |
3 |
Correct |
10 ms |
29016 KB |
Output is correct |
4 |
Correct |
18 ms |
29532 KB |
Output is correct |
5 |
Correct |
55 ms |
30260 KB |
Output is correct |
6 |
Correct |
9 ms |
29272 KB |
Output is correct |
7 |
Correct |
9 ms |
29016 KB |
Output is correct |
8 |
Correct |
9 ms |
29020 KB |
Output is correct |
9 |
Correct |
18 ms |
29020 KB |
Output is correct |
10 |
Correct |
95 ms |
29272 KB |
Output is correct |
11 |
Correct |
427 ms |
30804 KB |
Output is correct |
12 |
Correct |
11 ms |
29564 KB |
Output is correct |
13 |
Correct |
20 ms |
29528 KB |
Output is correct |
14 |
Correct |
87 ms |
29532 KB |
Output is correct |
15 |
Correct |
767 ms |
30040 KB |
Output is correct |
16 |
Correct |
3784 ms |
31104 KB |
Output is correct |
17 |
Correct |
55 ms |
41412 KB |
Output is correct |
18 |
Correct |
189 ms |
41396 KB |
Output is correct |
19 |
Correct |
1646 ms |
41808 KB |
Output is correct |
20 |
Execution timed out |
5053 ms |
41980 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
29276 KB |
Output is correct |
2 |
Correct |
98 ms |
29352 KB |
Output is correct |
3 |
Correct |
457 ms |
29896 KB |
Output is correct |
4 |
Correct |
904 ms |
30588 KB |
Output is correct |
5 |
Correct |
141 ms |
32244 KB |
Output is correct |
6 |
Correct |
1186 ms |
32224 KB |
Output is correct |
7 |
Execution timed out |
5056 ms |
32776 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5007 ms |
43440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
29016 KB |
Output is correct |
2 |
Correct |
8 ms |
29020 KB |
Output is correct |
3 |
Correct |
8 ms |
29016 KB |
Output is correct |
4 |
Correct |
8 ms |
29020 KB |
Output is correct |
5 |
Correct |
8 ms |
29136 KB |
Output is correct |
6 |
Correct |
8 ms |
29016 KB |
Output is correct |
7 |
Correct |
8 ms |
29184 KB |
Output is correct |
8 |
Correct |
8 ms |
29020 KB |
Output is correct |
9 |
Correct |
9 ms |
29172 KB |
Output is correct |
10 |
Correct |
9 ms |
29032 KB |
Output is correct |
11 |
Correct |
9 ms |
29020 KB |
Output is correct |
12 |
Correct |
10 ms |
29020 KB |
Output is correct |
13 |
Correct |
9 ms |
29172 KB |
Output is correct |
14 |
Correct |
9 ms |
29016 KB |
Output is correct |
15 |
Correct |
8 ms |
29020 KB |
Output is correct |
16 |
Correct |
9 ms |
29104 KB |
Output is correct |
17 |
Correct |
9 ms |
29016 KB |
Output is correct |
18 |
Correct |
8 ms |
29020 KB |
Output is correct |
19 |
Correct |
70 ms |
29272 KB |
Output is correct |
20 |
Correct |
72 ms |
29284 KB |
Output is correct |
21 |
Correct |
79 ms |
29320 KB |
Output is correct |
22 |
Correct |
114 ms |
29384 KB |
Output is correct |
23 |
Correct |
651 ms |
29644 KB |
Output is correct |
24 |
Correct |
791 ms |
29776 KB |
Output is correct |
25 |
Correct |
890 ms |
29728 KB |
Output is correct |
26 |
Correct |
1165 ms |
30288 KB |
Output is correct |
27 |
Correct |
9 ms |
29272 KB |
Output is correct |
28 |
Correct |
9 ms |
29020 KB |
Output is correct |
29 |
Correct |
10 ms |
29016 KB |
Output is correct |
30 |
Correct |
18 ms |
29532 KB |
Output is correct |
31 |
Correct |
55 ms |
30260 KB |
Output is correct |
32 |
Correct |
9 ms |
29272 KB |
Output is correct |
33 |
Correct |
9 ms |
29016 KB |
Output is correct |
34 |
Correct |
9 ms |
29020 KB |
Output is correct |
35 |
Correct |
18 ms |
29020 KB |
Output is correct |
36 |
Correct |
95 ms |
29272 KB |
Output is correct |
37 |
Correct |
427 ms |
30804 KB |
Output is correct |
38 |
Correct |
11 ms |
29564 KB |
Output is correct |
39 |
Correct |
20 ms |
29528 KB |
Output is correct |
40 |
Correct |
87 ms |
29532 KB |
Output is correct |
41 |
Correct |
767 ms |
30040 KB |
Output is correct |
42 |
Correct |
3784 ms |
31104 KB |
Output is correct |
43 |
Correct |
55 ms |
41412 KB |
Output is correct |
44 |
Correct |
189 ms |
41396 KB |
Output is correct |
45 |
Correct |
1646 ms |
41808 KB |
Output is correct |
46 |
Execution timed out |
5053 ms |
41980 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |