답안 #488762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488762 2021-11-20T11:51:08 Z cfalas Dynamic Diameter (CEOI19_diameter) C++14
24 / 100
5000 ms 11892 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n;
vi a, b;

vector<vii> adj;

ii f;

void dfs(int s, int p=-1, int d=0){
	if(d>f.F) f = max(f, {d, s});
	FOA(v, adj[s]){
		if(v.F!=p) dfs(v.F, s, d+v.S);
	}
}

int main(){
	int q;
	int w;
	cin>>n>>q>>w;
	adj.assign(n+1, vii());

	vector<pair<ii,ii> > edg(n-1);
	FOR(i,n-1){
		int a, b, c;
		cin>>a>>b>>c;
		edg[i] = {{a, adj[a].size()}, {b, adj[b].size()}};
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	int last=0;
	while(q--){
		int a, b;
		cin>>a>>b;
		a= (a + last) % (n-1);
		b = (b+last) % w;

		adj[edg[a].F.F][edg[a].F.S].S = b;
		adj[edg[a].S.F][edg[a].S.S].S = b;

		f = {0,1};
		dfs(1);
		dfs(f.S);

		last = f.F;
		cout<<last<<endl;

	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 112 ms 460 KB Output is correct
20 Correct 118 ms 456 KB Output is correct
21 Correct 162 ms 472 KB Output is correct
22 Correct 164 ms 500 KB Output is correct
23 Correct 819 ms 960 KB Output is correct
24 Correct 968 ms 1088 KB Output is correct
25 Correct 1014 ms 1156 KB Output is correct
26 Correct 1184 ms 1336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 5 ms 324 KB Output is correct
4 Correct 38 ms 508 KB Output is correct
5 Correct 191 ms 1328 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 12 ms 380 KB Output is correct
10 Correct 115 ms 584 KB Output is correct
11 Correct 556 ms 1624 KB Output is correct
12 Correct 5 ms 848 KB Output is correct
13 Correct 11 ms 848 KB Output is correct
14 Correct 82 ms 912 KB Output is correct
15 Correct 787 ms 1080 KB Output is correct
16 Correct 4232 ms 2272 KB Output is correct
17 Correct 83 ms 11640 KB Output is correct
18 Correct 225 ms 11648 KB Output is correct
19 Correct 1689 ms 11604 KB Output is correct
20 Execution timed out 5078 ms 11892 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 436 KB Output is correct
2 Correct 133 ms 504 KB Output is correct
3 Correct 630 ms 968 KB Output is correct
4 Correct 1272 ms 1736 KB Output is correct
5 Correct 123 ms 1552 KB Output is correct
6 Correct 1123 ms 1640 KB Output is correct
7 Execution timed out 5093 ms 2280 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 9372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 112 ms 460 KB Output is correct
20 Correct 118 ms 456 KB Output is correct
21 Correct 162 ms 472 KB Output is correct
22 Correct 164 ms 500 KB Output is correct
23 Correct 819 ms 960 KB Output is correct
24 Correct 968 ms 1088 KB Output is correct
25 Correct 1014 ms 1156 KB Output is correct
26 Correct 1184 ms 1336 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 5 ms 324 KB Output is correct
30 Correct 38 ms 508 KB Output is correct
31 Correct 191 ms 1328 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 12 ms 380 KB Output is correct
36 Correct 115 ms 584 KB Output is correct
37 Correct 556 ms 1624 KB Output is correct
38 Correct 5 ms 848 KB Output is correct
39 Correct 11 ms 848 KB Output is correct
40 Correct 82 ms 912 KB Output is correct
41 Correct 787 ms 1080 KB Output is correct
42 Correct 4232 ms 2272 KB Output is correct
43 Correct 83 ms 11640 KB Output is correct
44 Correct 225 ms 11648 KB Output is correct
45 Correct 1689 ms 11604 KB Output is correct
46 Execution timed out 5078 ms 11892 KB Time limit exceeded
47 Halted 0 ms 0 KB -