Submission #882520

# Submission time Handle Problem Language Result Execution time Memory
882520 2023-12-03T10:01:02 Z iskhakkutbilim Construction of Highway (JOI18_construction) C++17
7 / 100
2000 ms 24440 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) (a.begin(), a.end())

const int mod = 1e9 + 7;
const int N = 1e5;
int n, c[N+10];
vector<int> g[N+10], group[N+10];
int shortest[N+10];
int par[N+10];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n; i++){
		cin >> c[i];
		shortest[i] = -1;
	}
	int q = n-1;
	shortest[1] = 0;
	par[1] = -1; 
	group[1].push_back(1);
	while(q--){
		int a, b; cin >> a >> b;
		if(shortest[a] == -1 || shortest[b] > 0){
			assert(false);
		}
		
		int cost = 0;
		for(int s : group[a]){
			if(shortest[s] == -1) continue;
			for(int t : group[a]){
				if(shortest[t] == -1) continue;
				if(shortest[s] < shortest[t]){
					cost+= (c[s] > c[t]); 
				}
			}
		}
		g[a].push_back(b);
		for(int x : group[a]){
			group[b].push_back(x);
		}
		group[b].push_back(b);
		if(shortest[b] == -1 or shortest[b] > shortest[a]+1){
			shortest[b] = shortest[a] + 1;
			par[b] = a;
		}
		int parent = a;
		while(parent != -1){
			c[parent] = c[b];
			parent = par[parent];
		}
		cout << cost << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6680 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 47 ms 7772 KB Output is correct
9 Correct 37 ms 7844 KB Output is correct
10 Correct 37 ms 7772 KB Output is correct
11 Correct 11 ms 7260 KB Output is correct
12 Correct 11 ms 7140 KB Output is correct
13 Correct 13 ms 7056 KB Output is correct
14 Correct 12 ms 7260 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 16 ms 7216 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 12 ms 7184 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 37 ms 7808 KB Output is correct
27 Correct 12 ms 7260 KB Output is correct
28 Correct 11 ms 7120 KB Output is correct
29 Correct 12 ms 7260 KB Output is correct
30 Correct 2 ms 6584 KB Output is correct
31 Correct 2 ms 6488 KB Output is correct
32 Correct 12 ms 7308 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 3 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 4 ms 6748 KB Output is correct
37 Correct 4 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 5 ms 6812 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 4 ms 6748 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6680 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 47 ms 7772 KB Output is correct
9 Correct 37 ms 7844 KB Output is correct
10 Correct 37 ms 7772 KB Output is correct
11 Correct 11 ms 7260 KB Output is correct
12 Correct 11 ms 7140 KB Output is correct
13 Correct 13 ms 7056 KB Output is correct
14 Correct 12 ms 7260 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 16 ms 7216 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 12 ms 7184 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 37 ms 7808 KB Output is correct
27 Correct 12 ms 7260 KB Output is correct
28 Correct 11 ms 7120 KB Output is correct
29 Correct 12 ms 7260 KB Output is correct
30 Correct 2 ms 6584 KB Output is correct
31 Correct 2 ms 6488 KB Output is correct
32 Correct 12 ms 7308 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 3 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 4 ms 6748 KB Output is correct
37 Correct 4 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 5 ms 6812 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 4 ms 6748 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 4 ms 7004 KB Output is correct
47 Correct 4 ms 7004 KB Output is correct
48 Correct 3 ms 7004 KB Output is correct
49 Execution timed out 2089 ms 24440 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6680 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 47 ms 7772 KB Output is correct
9 Correct 37 ms 7844 KB Output is correct
10 Correct 37 ms 7772 KB Output is correct
11 Correct 11 ms 7260 KB Output is correct
12 Correct 11 ms 7140 KB Output is correct
13 Correct 13 ms 7056 KB Output is correct
14 Correct 12 ms 7260 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 16 ms 7216 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 12 ms 7184 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 37 ms 7808 KB Output is correct
27 Correct 12 ms 7260 KB Output is correct
28 Correct 11 ms 7120 KB Output is correct
29 Correct 12 ms 7260 KB Output is correct
30 Correct 2 ms 6584 KB Output is correct
31 Correct 2 ms 6488 KB Output is correct
32 Correct 12 ms 7308 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 3 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 4 ms 6748 KB Output is correct
37 Correct 4 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 5 ms 6812 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 4 ms 6748 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 4 ms 7004 KB Output is correct
47 Correct 4 ms 7004 KB Output is correct
48 Correct 3 ms 7004 KB Output is correct
49 Execution timed out 2089 ms 24440 KB Time limit exceeded
50 Halted 0 ms 0 KB -