Submission #1038016

# Submission time Handle Problem Language Result Execution time Memory
1038016 2024-07-29T12:07:19 Z Unforgettablepl JOI tour (JOI24_joitour) C++17
20 / 100
3000 ms 36384 KB
#include "joitour.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> adj;
vector<int> type;

void init(int N, vector<int> F, vector<int> U, vector<int> V,
		  int Q) {
	adj = vector<vector<int>> (N);
	type = F;
	for(int i=0;i<N-1;i++){
		adj[U[i]].emplace_back(V[i]);
		adj[V[i]].emplace_back(U[i]);
	}
}

void change(int X, int Y){
	type[X]=Y;
}

long long num_tours(){
	vector<long long> tot(3);
	for(int&i:type)tot[i]++;
	long long ans = tot[0]*tot[1]*tot[2];
	function<pair<long long,long long>(int,int)> dfs = [&](int x,int p){
		if(type[x]!=1){
			pair<long long,long long> mytot = {0,0};
			if(type[x]==0)mytot.first++;
			else mytot.second++;
			for(int&i:adj[x])if(i!=p){
				auto t = dfs(i,x);
				mytot.first+=t.first;
				mytot.second+=t.second;
			}
			return mytot;
		}
		pair<long long,long long> mytot = {0,0};
		for(int&i:adj[x])if(i!=p){
			auto t = dfs(i,x);
			ans-=t.first*t.second;
			mytot.first+=t.first;
			mytot.second+=t.second;
		}
		ans-=(tot[0]-mytot.first)*(tot[2]-mytot.second);
		return mytot;
	};
	dfs(0,-1);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 104 ms 856 KB Output is correct
26 Correct 56 ms 600 KB Output is correct
27 Correct 33 ms 600 KB Output is correct
28 Correct 72 ms 1112 KB Output is correct
29 Correct 33 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 69 ms 27512 KB Output is correct
3 Correct 66 ms 26980 KB Output is correct
4 Correct 94 ms 22964 KB Output is correct
5 Correct 78 ms 28352 KB Output is correct
6 Correct 44 ms 16720 KB Output is correct
7 Correct 51 ms 16852 KB Output is correct
8 Correct 75 ms 16740 KB Output is correct
9 Correct 62 ms 16868 KB Output is correct
10 Correct 63 ms 16696 KB Output is correct
11 Correct 62 ms 16720 KB Output is correct
12 Correct 63 ms 21024 KB Output is correct
13 Correct 65 ms 21024 KB Output is correct
14 Correct 75 ms 20644 KB Output is correct
15 Correct 95 ms 19692 KB Output is correct
16 Correct 78 ms 31588 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 72 ms 16852 KB Output is correct
22 Correct 90 ms 16852 KB Output is correct
23 Correct 97 ms 16788 KB Output is correct
24 Correct 96 ms 16720 KB Output is correct
25 Correct 54 ms 17604 KB Output is correct
26 Correct 52 ms 17456 KB Output is correct
27 Correct 52 ms 17436 KB Output is correct
28 Correct 52 ms 17496 KB Output is correct
29 Correct 62 ms 36384 KB Output is correct
30 Correct 60 ms 36256 KB Output is correct
31 Correct 60 ms 36376 KB Output is correct
32 Correct 59 ms 36260 KB Output is correct
33 Correct 50 ms 16720 KB Output is correct
34 Correct 50 ms 17048 KB Output is correct
35 Correct 44 ms 16716 KB Output is correct
36 Correct 45 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 60 ms 1112 KB Output is correct
9 Correct 58 ms 36260 KB Output is correct
10 Correct 63 ms 36212 KB Output is correct
11 Correct 55 ms 36384 KB Output is correct
12 Correct 64 ms 36384 KB Output is correct
13 Execution timed out 3036 ms 18420 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 35 ms 600 KB Output is correct
8 Correct 51 ms 16784 KB Output is correct
9 Correct 48 ms 16720 KB Output is correct
10 Correct 49 ms 16720 KB Output is correct
11 Correct 50 ms 16852 KB Output is correct
12 Execution timed out 3015 ms 8536 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 104 ms 856 KB Output is correct
26 Correct 56 ms 600 KB Output is correct
27 Correct 33 ms 600 KB Output is correct
28 Correct 72 ms 1112 KB Output is correct
29 Correct 33 ms 600 KB Output is correct
30 Execution timed out 3021 ms 11192 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 104 ms 856 KB Output is correct
26 Correct 56 ms 600 KB Output is correct
27 Correct 33 ms 600 KB Output is correct
28 Correct 72 ms 1112 KB Output is correct
29 Correct 33 ms 600 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 69 ms 27512 KB Output is correct
32 Correct 66 ms 26980 KB Output is correct
33 Correct 94 ms 22964 KB Output is correct
34 Correct 78 ms 28352 KB Output is correct
35 Correct 44 ms 16720 KB Output is correct
36 Correct 51 ms 16852 KB Output is correct
37 Correct 75 ms 16740 KB Output is correct
38 Correct 62 ms 16868 KB Output is correct
39 Correct 63 ms 16696 KB Output is correct
40 Correct 62 ms 16720 KB Output is correct
41 Correct 63 ms 21024 KB Output is correct
42 Correct 65 ms 21024 KB Output is correct
43 Correct 75 ms 20644 KB Output is correct
44 Correct 95 ms 19692 KB Output is correct
45 Correct 78 ms 31588 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 72 ms 16852 KB Output is correct
51 Correct 90 ms 16852 KB Output is correct
52 Correct 97 ms 16788 KB Output is correct
53 Correct 96 ms 16720 KB Output is correct
54 Correct 54 ms 17604 KB Output is correct
55 Correct 52 ms 17456 KB Output is correct
56 Correct 52 ms 17436 KB Output is correct
57 Correct 52 ms 17496 KB Output is correct
58 Correct 62 ms 36384 KB Output is correct
59 Correct 60 ms 36256 KB Output is correct
60 Correct 60 ms 36376 KB Output is correct
61 Correct 59 ms 36260 KB Output is correct
62 Correct 50 ms 16720 KB Output is correct
63 Correct 50 ms 17048 KB Output is correct
64 Correct 44 ms 16716 KB Output is correct
65 Correct 45 ms 16720 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 60 ms 1112 KB Output is correct
74 Correct 58 ms 36260 KB Output is correct
75 Correct 63 ms 36212 KB Output is correct
76 Correct 55 ms 36384 KB Output is correct
77 Correct 64 ms 36384 KB Output is correct
78 Execution timed out 3036 ms 18420 KB Time limit exceeded
79 Halted 0 ms 0 KB -