답안 #48957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48957 2018-05-20T14:22:28 Z mrtsima22 Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 5632 KB
#include <iostream>
#include <vector>
using namespace std;
int n,k,q,t_out[100003],fin,p[100003];
vector<int>a[100003];
int b[100003],t_in[100004],T,x;
bool is_it(int a,int b)
{
	return (t_in[a]<=t_in[b])&&(t_out[b]<=t_out[a]);
}
void go(int s,int parent)
{
	t_in[s]=++T;
	p[s]=parent;
	for(int i=0;i<a[s].size();i++)
	{
		if(a[s][i]==parent)continue;
		go(a[s][i],s);
	}
	t_out[s]=++T;
}
int u,v,tp;
int main() {ios_base::sync_with_stdio(false);
cin>>n>>k>>q;
for(int i=0;i<n-1;i++)
{
	cin>>v>>u;
	a[v].push_back(u);
	a[u].push_back(v);
}
for(int i=1;i<=k;i++)
{
	cin>>b[i];
}
go(1,0);
t_out[0]=999999999;
while(q--)
{
	cin>>tp;
	if(tp==1)
	{
		cin>>u>>v;
		b[u]=v;
	}
	else if(tp==2){
	cin>>u>>v>>x;
	fin=0;
		for(int L=u;!fin&&L<=v;L++)
		{
			int c=b[L];
			for(int R=L;!fin&&R<=v;R++)
			{
				while(!is_it(c,b[R]))c=p[c];
				if(!is_it(x,c))break;
				if(x==c)
				{
					fin=1;
					cout<<L<<" "<<R<<endl;
				}
			}
		}
		if(!fin)
		{
			cout<<"-1 -1"<<endl;
		}
	}
	
}


	return 0;
}

Compilation message

treearray.cpp: In function 'void go(int, int)':
treearray.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[s].size();i++)
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB n=5
2 Correct 4 ms 2808 KB n=100
3 Correct 4 ms 2964 KB n=100
4 Correct 5 ms 3112 KB n=100
5 Correct 5 ms 3188 KB n=100
6 Correct 4 ms 3188 KB n=100
7 Correct 4 ms 3188 KB n=100
8 Correct 5 ms 3188 KB n=100
9 Correct 5 ms 3228 KB n=100
10 Correct 5 ms 3228 KB n=100
11 Correct 5 ms 3228 KB n=100
12 Correct 5 ms 3228 KB n=100
13 Correct 5 ms 3228 KB n=100
14 Correct 5 ms 3228 KB n=100
15 Correct 5 ms 3228 KB n=100
16 Correct 6 ms 3264 KB n=100
17 Correct 5 ms 3324 KB n=100
18 Correct 5 ms 3324 KB n=100
19 Correct 5 ms 3324 KB n=100
20 Correct 5 ms 3404 KB n=100
21 Correct 5 ms 3404 KB n=100
22 Correct 5 ms 3404 KB n=100
23 Correct 6 ms 3404 KB n=100
24 Correct 6 ms 3404 KB n=100
25 Correct 5 ms 3404 KB n=100
26 Correct 3 ms 3404 KB n=12
27 Correct 5 ms 3404 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB n=5
2 Correct 4 ms 2808 KB n=100
3 Correct 4 ms 2964 KB n=100
4 Correct 5 ms 3112 KB n=100
5 Correct 5 ms 3188 KB n=100
6 Correct 4 ms 3188 KB n=100
7 Correct 4 ms 3188 KB n=100
8 Correct 5 ms 3188 KB n=100
9 Correct 5 ms 3228 KB n=100
10 Correct 5 ms 3228 KB n=100
11 Correct 5 ms 3228 KB n=100
12 Correct 5 ms 3228 KB n=100
13 Correct 5 ms 3228 KB n=100
14 Correct 5 ms 3228 KB n=100
15 Correct 5 ms 3228 KB n=100
16 Correct 6 ms 3264 KB n=100
17 Correct 5 ms 3324 KB n=100
18 Correct 5 ms 3324 KB n=100
19 Correct 5 ms 3324 KB n=100
20 Correct 5 ms 3404 KB n=100
21 Correct 5 ms 3404 KB n=100
22 Correct 5 ms 3404 KB n=100
23 Correct 6 ms 3404 KB n=100
24 Correct 6 ms 3404 KB n=100
25 Correct 5 ms 3404 KB n=100
26 Correct 3 ms 3404 KB n=12
27 Correct 5 ms 3404 KB n=100
28 Correct 5 ms 3404 KB n=500
29 Correct 14 ms 3404 KB n=500
30 Correct 10 ms 3432 KB n=500
31 Correct 12 ms 3464 KB n=500
32 Correct 5 ms 3464 KB n=500
33 Correct 10 ms 3464 KB n=500
34 Correct 6 ms 3464 KB n=500
35 Correct 15 ms 3464 KB n=500
36 Correct 8 ms 3464 KB n=500
37 Correct 7 ms 3464 KB n=500
38 Correct 7 ms 3484 KB n=500
39 Correct 6 ms 3484 KB n=500
40 Correct 7 ms 3492 KB n=500
41 Correct 8 ms 3508 KB n=500
42 Correct 6 ms 3524 KB n=500
43 Correct 6 ms 3540 KB n=500
44 Correct 6 ms 3620 KB n=500
45 Correct 6 ms 3620 KB n=500
46 Correct 16 ms 3620 KB n=500
47 Correct 13 ms 3620 KB n=500
48 Correct 5 ms 3620 KB n=500
49 Correct 12 ms 3748 KB n=500
50 Correct 6 ms 3748 KB n=500
51 Correct 10 ms 3748 KB n=500
52 Correct 19 ms 3748 KB n=500
53 Correct 8 ms 3748 KB n=500
54 Correct 31 ms 3748 KB n=500
55 Correct 6 ms 3748 KB n=278
56 Correct 149 ms 3748 KB n=500
57 Correct 159 ms 3748 KB n=500
58 Correct 6 ms 3748 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB n=5
2 Correct 4 ms 2808 KB n=100
3 Correct 4 ms 2964 KB n=100
4 Correct 5 ms 3112 KB n=100
5 Correct 5 ms 3188 KB n=100
6 Correct 4 ms 3188 KB n=100
7 Correct 4 ms 3188 KB n=100
8 Correct 5 ms 3188 KB n=100
9 Correct 5 ms 3228 KB n=100
10 Correct 5 ms 3228 KB n=100
11 Correct 5 ms 3228 KB n=100
12 Correct 5 ms 3228 KB n=100
13 Correct 5 ms 3228 KB n=100
14 Correct 5 ms 3228 KB n=100
15 Correct 5 ms 3228 KB n=100
16 Correct 6 ms 3264 KB n=100
17 Correct 5 ms 3324 KB n=100
18 Correct 5 ms 3324 KB n=100
19 Correct 5 ms 3324 KB n=100
20 Correct 5 ms 3404 KB n=100
21 Correct 5 ms 3404 KB n=100
22 Correct 5 ms 3404 KB n=100
23 Correct 6 ms 3404 KB n=100
24 Correct 6 ms 3404 KB n=100
25 Correct 5 ms 3404 KB n=100
26 Correct 3 ms 3404 KB n=12
27 Correct 5 ms 3404 KB n=100
28 Correct 5 ms 3404 KB n=500
29 Correct 14 ms 3404 KB n=500
30 Correct 10 ms 3432 KB n=500
31 Correct 12 ms 3464 KB n=500
32 Correct 5 ms 3464 KB n=500
33 Correct 10 ms 3464 KB n=500
34 Correct 6 ms 3464 KB n=500
35 Correct 15 ms 3464 KB n=500
36 Correct 8 ms 3464 KB n=500
37 Correct 7 ms 3464 KB n=500
38 Correct 7 ms 3484 KB n=500
39 Correct 6 ms 3484 KB n=500
40 Correct 7 ms 3492 KB n=500
41 Correct 8 ms 3508 KB n=500
42 Correct 6 ms 3524 KB n=500
43 Correct 6 ms 3540 KB n=500
44 Correct 6 ms 3620 KB n=500
45 Correct 6 ms 3620 KB n=500
46 Correct 16 ms 3620 KB n=500
47 Correct 13 ms 3620 KB n=500
48 Correct 5 ms 3620 KB n=500
49 Correct 12 ms 3748 KB n=500
50 Correct 6 ms 3748 KB n=500
51 Correct 10 ms 3748 KB n=500
52 Correct 19 ms 3748 KB n=500
53 Correct 8 ms 3748 KB n=500
54 Correct 31 ms 3748 KB n=500
55 Correct 6 ms 3748 KB n=278
56 Correct 149 ms 3748 KB n=500
57 Correct 159 ms 3748 KB n=500
58 Correct 6 ms 3748 KB n=500
59 Correct 9 ms 3884 KB n=2000
60 Correct 556 ms 4120 KB n=2000
61 Correct 342 ms 4152 KB n=2000
62 Correct 135 ms 4152 KB n=2000
63 Correct 8 ms 4172 KB n=2000
64 Correct 231 ms 4288 KB n=2000
65 Correct 8 ms 4288 KB n=2000
66 Correct 449 ms 4524 KB n=2000
67 Correct 9 ms 4524 KB n=2000
68 Correct 290 ms 4636 KB n=2000
69 Correct 45 ms 4636 KB n=2000
70 Correct 46 ms 4636 KB n=2000
71 Correct 43 ms 4668 KB n=2000
72 Correct 27 ms 4668 KB n=2000
73 Correct 30 ms 4668 KB n=2000
74 Correct 12 ms 4704 KB n=1844
75 Correct 29 ms 4828 KB n=2000
76 Correct 25 ms 4828 KB n=2000
77 Correct 25 ms 4856 KB n=2000
78 Correct 32 ms 5068 KB n=2000
79 Correct 10 ms 5068 KB n=2000
80 Correct 402 ms 5168 KB n=2000
81 Correct 215 ms 5224 KB n=2000
82 Correct 8 ms 5224 KB n=2000
83 Correct 351 ms 5432 KB n=2000
84 Correct 13 ms 5432 KB n=2000
85 Correct 166 ms 5496 KB n=2000
86 Correct 93 ms 5496 KB n=2000
87 Correct 14 ms 5496 KB n=2000
88 Execution timed out 4014 ms 5632 KB Time limit exceeded
89 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB n=5
2 Correct 4 ms 2808 KB n=100
3 Correct 4 ms 2964 KB n=100
4 Correct 5 ms 3112 KB n=100
5 Correct 5 ms 3188 KB n=100
6 Correct 4 ms 3188 KB n=100
7 Correct 4 ms 3188 KB n=100
8 Correct 5 ms 3188 KB n=100
9 Correct 5 ms 3228 KB n=100
10 Correct 5 ms 3228 KB n=100
11 Correct 5 ms 3228 KB n=100
12 Correct 5 ms 3228 KB n=100
13 Correct 5 ms 3228 KB n=100
14 Correct 5 ms 3228 KB n=100
15 Correct 5 ms 3228 KB n=100
16 Correct 6 ms 3264 KB n=100
17 Correct 5 ms 3324 KB n=100
18 Correct 5 ms 3324 KB n=100
19 Correct 5 ms 3324 KB n=100
20 Correct 5 ms 3404 KB n=100
21 Correct 5 ms 3404 KB n=100
22 Correct 5 ms 3404 KB n=100
23 Correct 6 ms 3404 KB n=100
24 Correct 6 ms 3404 KB n=100
25 Correct 5 ms 3404 KB n=100
26 Correct 3 ms 3404 KB n=12
27 Correct 5 ms 3404 KB n=100
28 Correct 5 ms 3404 KB n=500
29 Correct 14 ms 3404 KB n=500
30 Correct 10 ms 3432 KB n=500
31 Correct 12 ms 3464 KB n=500
32 Correct 5 ms 3464 KB n=500
33 Correct 10 ms 3464 KB n=500
34 Correct 6 ms 3464 KB n=500
35 Correct 15 ms 3464 KB n=500
36 Correct 8 ms 3464 KB n=500
37 Correct 7 ms 3464 KB n=500
38 Correct 7 ms 3484 KB n=500
39 Correct 6 ms 3484 KB n=500
40 Correct 7 ms 3492 KB n=500
41 Correct 8 ms 3508 KB n=500
42 Correct 6 ms 3524 KB n=500
43 Correct 6 ms 3540 KB n=500
44 Correct 6 ms 3620 KB n=500
45 Correct 6 ms 3620 KB n=500
46 Correct 16 ms 3620 KB n=500
47 Correct 13 ms 3620 KB n=500
48 Correct 5 ms 3620 KB n=500
49 Correct 12 ms 3748 KB n=500
50 Correct 6 ms 3748 KB n=500
51 Correct 10 ms 3748 KB n=500
52 Correct 19 ms 3748 KB n=500
53 Correct 8 ms 3748 KB n=500
54 Correct 31 ms 3748 KB n=500
55 Correct 6 ms 3748 KB n=278
56 Correct 149 ms 3748 KB n=500
57 Correct 159 ms 3748 KB n=500
58 Correct 6 ms 3748 KB n=500
59 Correct 9 ms 3884 KB n=2000
60 Correct 556 ms 4120 KB n=2000
61 Correct 342 ms 4152 KB n=2000
62 Correct 135 ms 4152 KB n=2000
63 Correct 8 ms 4172 KB n=2000
64 Correct 231 ms 4288 KB n=2000
65 Correct 8 ms 4288 KB n=2000
66 Correct 449 ms 4524 KB n=2000
67 Correct 9 ms 4524 KB n=2000
68 Correct 290 ms 4636 KB n=2000
69 Correct 45 ms 4636 KB n=2000
70 Correct 46 ms 4636 KB n=2000
71 Correct 43 ms 4668 KB n=2000
72 Correct 27 ms 4668 KB n=2000
73 Correct 30 ms 4668 KB n=2000
74 Correct 12 ms 4704 KB n=1844
75 Correct 29 ms 4828 KB n=2000
76 Correct 25 ms 4828 KB n=2000
77 Correct 25 ms 4856 KB n=2000
78 Correct 32 ms 5068 KB n=2000
79 Correct 10 ms 5068 KB n=2000
80 Correct 402 ms 5168 KB n=2000
81 Correct 215 ms 5224 KB n=2000
82 Correct 8 ms 5224 KB n=2000
83 Correct 351 ms 5432 KB n=2000
84 Correct 13 ms 5432 KB n=2000
85 Correct 166 ms 5496 KB n=2000
86 Correct 93 ms 5496 KB n=2000
87 Correct 14 ms 5496 KB n=2000
88 Execution timed out 4014 ms 5632 KB Time limit exceeded
89 Halted 0 ms 0 KB -