답안 #882518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882518 2023-12-03T10:00:50 Z iskhakkutbilim Construction of Highway (JOI18_construction) C++17
7 / 100
2000 ms 22988 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) continue;
		
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6556 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 61 ms 7740 KB Output is correct
9 Correct 54 ms 7760 KB Output is correct
10 Correct 56 ms 7768 KB Output is correct
11 Correct 12 ms 7260 KB Output is correct
12 Correct 16 ms 7092 KB Output is correct
13 Correct 14 ms 7260 KB Output is correct
14 Correct 17 ms 7132 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6592 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 16 ms 7224 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 18 ms 7252 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6620 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 40 ms 7868 KB Output is correct
27 Correct 11 ms 7260 KB Output is correct
28 Correct 15 ms 7260 KB Output is correct
29 Correct 11 ms 7260 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 17 ms 7260 KB Output is correct
33 Correct 5 ms 6748 KB Output is correct
34 Correct 5 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 5 ms 6744 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 4 ms 6996 KB Output is correct
39 Correct 5 ms 6748 KB Output is correct
40 Correct 4 ms 6748 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 5 ms 6748 KB Output is correct
43 Correct 4 ms 6880 KB Output is correct
44 Correct 3 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6556 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 61 ms 7740 KB Output is correct
9 Correct 54 ms 7760 KB Output is correct
10 Correct 56 ms 7768 KB Output is correct
11 Correct 12 ms 7260 KB Output is correct
12 Correct 16 ms 7092 KB Output is correct
13 Correct 14 ms 7260 KB Output is correct
14 Correct 17 ms 7132 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6592 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 16 ms 7224 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 18 ms 7252 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6620 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 40 ms 7868 KB Output is correct
27 Correct 11 ms 7260 KB Output is correct
28 Correct 15 ms 7260 KB Output is correct
29 Correct 11 ms 7260 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 17 ms 7260 KB Output is correct
33 Correct 5 ms 6748 KB Output is correct
34 Correct 5 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 5 ms 6744 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 4 ms 6996 KB Output is correct
39 Correct 5 ms 6748 KB Output is correct
40 Correct 4 ms 6748 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 5 ms 6748 KB Output is correct
43 Correct 4 ms 6880 KB Output is correct
44 Correct 3 ms 6744 KB Output is correct
45 Correct 2 ms 6744 KB Output is correct
46 Correct 4 ms 7260 KB Output is correct
47 Correct 4 ms 7260 KB Output is correct
48 Correct 4 ms 7004 KB Output is correct
49 Execution timed out 2087 ms 22988 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6556 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 61 ms 7740 KB Output is correct
9 Correct 54 ms 7760 KB Output is correct
10 Correct 56 ms 7768 KB Output is correct
11 Correct 12 ms 7260 KB Output is correct
12 Correct 16 ms 7092 KB Output is correct
13 Correct 14 ms 7260 KB Output is correct
14 Correct 17 ms 7132 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6592 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 16 ms 7224 KB Output is correct
20 Correct 12 ms 7260 KB Output is correct
21 Correct 18 ms 7252 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6620 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 40 ms 7868 KB Output is correct
27 Correct 11 ms 7260 KB Output is correct
28 Correct 15 ms 7260 KB Output is correct
29 Correct 11 ms 7260 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 17 ms 7260 KB Output is correct
33 Correct 5 ms 6748 KB Output is correct
34 Correct 5 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 5 ms 6744 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 4 ms 6996 KB Output is correct
39 Correct 5 ms 6748 KB Output is correct
40 Correct 4 ms 6748 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 5 ms 6748 KB Output is correct
43 Correct 4 ms 6880 KB Output is correct
44 Correct 3 ms 6744 KB Output is correct
45 Correct 2 ms 6744 KB Output is correct
46 Correct 4 ms 7260 KB Output is correct
47 Correct 4 ms 7260 KB Output is correct
48 Correct 4 ms 7004 KB Output is correct
49 Execution timed out 2087 ms 22988 KB Time limit exceeded
50 Halted 0 ms 0 KB -