답안 #1095703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095703 2024-10-03T02:47:13 Z zaza Construction Project 2 (JOI24_ho_t2) C++14
100 / 100
158 ms 27836 KB
#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> g[200005];

long long d[2][200005];

void dij(int i, int s) {
	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
	q.emplace(0, s);
	d[i][s] = 0;
	while (q.size()) {
		int u = q.top().second;
		long long dl = q.top().first;
		q.pop();
		if (dl > d[i][u]) {
			continue;
		}
		for (pair<int, int> p: g[u]) {
			int v = p.first, w = p.second;
			if (d[i][v] > d[i][u] + w) {
				d[i][v] = d[i][u] + w;
				q.emplace(d[i][v], v);
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m, s, t, l;
	long long k;
	
	cin >> n >> m >> s >> t >> l >> k;
		
	for (int i = 1; i <= m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}

	memset(d, 0x3f3f3f3f, sizeof d);
	
	dij(0, s);
	dij(1, t);
	
	if (d[0][t] <= k) {
		cout << 1ll * n * (n - 1) / 2 << '\n';
		return 0;
	}
	
	vector<long long> v;
	
	for (int i = 1; i <= n; ++i) {
		v.emplace_back(d[1][i]);
	}
	
	sort(v.begin(), v.end());
	
	long long ans = 0;
	
	for (int i = 1; i <= n; ++i) {
		int j = upper_bound(v.begin(), v.end(), k - l - d[0][i]) - v.begin();
		if (d[1][i] <= k - l - d[0][i]) {
			j--;
		}
		ans += j;
	}
	
	cout << ans << '\n';
	
}
/*
18 21
4 8 678730772 3000000062
5 13 805281073
8 17 80983648
3 8 996533440
10 16 514277428
2 5 57914340
6 11 966149890
8 12 532734310
2 9 188599710
2 3 966306014
12 16 656457780
16 18 662633078
1 15 698078877
2 8 665665772
2 6 652261981
14 15 712798281
7 13 571169114
13 14 860543313
6 7 454251187
9 14 293590683
6 14 959532841
3 11 591245645
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 4 ms 8192 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 56 ms 20360 KB Output is correct
8 Correct 65 ms 20332 KB Output is correct
9 Correct 69 ms 20844 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 5 ms 8280 KB Output is correct
14 Correct 36 ms 16088 KB Output is correct
15 Correct 129 ms 20368 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 63 ms 19472 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 4 ms 8404 KB Output is correct
23 Correct 39 ms 16080 KB Output is correct
24 Correct 129 ms 20236 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 4 ms 8540 KB Output is correct
27 Correct 79 ms 26284 KB Output is correct
28 Correct 62 ms 18840 KB Output is correct
29 Correct 54 ms 18376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8024 KB Output is correct
2 Correct 4 ms 8024 KB Output is correct
3 Correct 3 ms 8280 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 5 ms 8280 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 4 ms 8280 KB Output is correct
8 Correct 4 ms 8060 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 4 ms 8044 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8232 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 4 ms 8028 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 3 ms 8284 KB Output is correct
23 Correct 4 ms 8184 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 3 ms 8240 KB Output is correct
26 Correct 4 ms 8284 KB Output is correct
27 Correct 4 ms 8232 KB Output is correct
28 Correct 4 ms 8280 KB Output is correct
29 Correct 4 ms 8284 KB Output is correct
30 Correct 4 ms 8284 KB Output is correct
31 Correct 3 ms 8284 KB Output is correct
32 Correct 3 ms 8228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8024 KB Output is correct
2 Correct 4 ms 8024 KB Output is correct
3 Correct 3 ms 8280 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 5 ms 8280 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 4 ms 8280 KB Output is correct
8 Correct 4 ms 8060 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 4 ms 8044 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8232 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 4 ms 8028 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 3 ms 8284 KB Output is correct
23 Correct 4 ms 8184 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 3 ms 8240 KB Output is correct
26 Correct 4 ms 8284 KB Output is correct
27 Correct 4 ms 8232 KB Output is correct
28 Correct 4 ms 8280 KB Output is correct
29 Correct 4 ms 8284 KB Output is correct
30 Correct 4 ms 8284 KB Output is correct
31 Correct 3 ms 8284 KB Output is correct
32 Correct 3 ms 8228 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 4 ms 8280 KB Output is correct
35 Correct 4 ms 8284 KB Output is correct
36 Correct 6 ms 8284 KB Output is correct
37 Correct 4 ms 8380 KB Output is correct
38 Correct 4 ms 8284 KB Output is correct
39 Correct 4 ms 8284 KB Output is correct
40 Correct 5 ms 8536 KB Output is correct
41 Correct 4 ms 8308 KB Output is correct
42 Correct 4 ms 8284 KB Output is correct
43 Correct 6 ms 8284 KB Output is correct
44 Correct 6 ms 8284 KB Output is correct
45 Correct 5 ms 8284 KB Output is correct
46 Correct 5 ms 8280 KB Output is correct
47 Correct 5 ms 8496 KB Output is correct
48 Correct 5 ms 8284 KB Output is correct
49 Correct 4 ms 8284 KB Output is correct
50 Correct 4 ms 8284 KB Output is correct
51 Correct 5 ms 8280 KB Output is correct
52 Correct 6 ms 8284 KB Output is correct
53 Correct 5 ms 8540 KB Output is correct
54 Correct 5 ms 8536 KB Output is correct
55 Correct 4 ms 8284 KB Output is correct
56 Correct 5 ms 8456 KB Output is correct
57 Correct 5 ms 8284 KB Output is correct
58 Correct 5 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 4 ms 8192 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 56 ms 20360 KB Output is correct
8 Correct 65 ms 20332 KB Output is correct
9 Correct 69 ms 20844 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 5 ms 8280 KB Output is correct
14 Correct 36 ms 16088 KB Output is correct
15 Correct 129 ms 20368 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 63 ms 19472 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 4 ms 8404 KB Output is correct
23 Correct 39 ms 16080 KB Output is correct
24 Correct 129 ms 20236 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 4 ms 8540 KB Output is correct
27 Correct 79 ms 26284 KB Output is correct
28 Correct 62 ms 18840 KB Output is correct
29 Correct 54 ms 18376 KB Output is correct
30 Correct 3 ms 8024 KB Output is correct
31 Correct 4 ms 8024 KB Output is correct
32 Correct 3 ms 8280 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 5 ms 8280 KB Output is correct
35 Correct 3 ms 8284 KB Output is correct
36 Correct 4 ms 8280 KB Output is correct
37 Correct 4 ms 8060 KB Output is correct
38 Correct 4 ms 8284 KB Output is correct
39 Correct 4 ms 8284 KB Output is correct
40 Correct 4 ms 8536 KB Output is correct
41 Correct 4 ms 8044 KB Output is correct
42 Correct 4 ms 8284 KB Output is correct
43 Correct 4 ms 8232 KB Output is correct
44 Correct 4 ms 8284 KB Output is correct
45 Correct 4 ms 8284 KB Output is correct
46 Correct 4 ms 8284 KB Output is correct
47 Correct 4 ms 8028 KB Output is correct
48 Correct 3 ms 8284 KB Output is correct
49 Correct 3 ms 8284 KB Output is correct
50 Correct 5 ms 8284 KB Output is correct
51 Correct 3 ms 8284 KB Output is correct
52 Correct 4 ms 8184 KB Output is correct
53 Correct 4 ms 8280 KB Output is correct
54 Correct 3 ms 8240 KB Output is correct
55 Correct 4 ms 8284 KB Output is correct
56 Correct 4 ms 8232 KB Output is correct
57 Correct 4 ms 8280 KB Output is correct
58 Correct 4 ms 8284 KB Output is correct
59 Correct 4 ms 8284 KB Output is correct
60 Correct 3 ms 8284 KB Output is correct
61 Correct 3 ms 8228 KB Output is correct
62 Correct 4 ms 8284 KB Output is correct
63 Correct 4 ms 8280 KB Output is correct
64 Correct 4 ms 8284 KB Output is correct
65 Correct 6 ms 8284 KB Output is correct
66 Correct 4 ms 8380 KB Output is correct
67 Correct 4 ms 8284 KB Output is correct
68 Correct 4 ms 8284 KB Output is correct
69 Correct 5 ms 8536 KB Output is correct
70 Correct 4 ms 8308 KB Output is correct
71 Correct 4 ms 8284 KB Output is correct
72 Correct 6 ms 8284 KB Output is correct
73 Correct 6 ms 8284 KB Output is correct
74 Correct 5 ms 8284 KB Output is correct
75 Correct 5 ms 8280 KB Output is correct
76 Correct 5 ms 8496 KB Output is correct
77 Correct 5 ms 8284 KB Output is correct
78 Correct 4 ms 8284 KB Output is correct
79 Correct 4 ms 8284 KB Output is correct
80 Correct 5 ms 8280 KB Output is correct
81 Correct 6 ms 8284 KB Output is correct
82 Correct 5 ms 8540 KB Output is correct
83 Correct 5 ms 8536 KB Output is correct
84 Correct 4 ms 8284 KB Output is correct
85 Correct 5 ms 8456 KB Output is correct
86 Correct 5 ms 8284 KB Output is correct
87 Correct 5 ms 8280 KB Output is correct
88 Correct 81 ms 20308 KB Output is correct
89 Correct 94 ms 20328 KB Output is correct
90 Correct 83 ms 21928 KB Output is correct
91 Correct 37 ms 17240 KB Output is correct
92 Correct 37 ms 17172 KB Output is correct
93 Correct 45 ms 16844 KB Output is correct
94 Correct 38 ms 16844 KB Output is correct
95 Correct 153 ms 22804 KB Output is correct
96 Correct 123 ms 21160 KB Output is correct
97 Correct 127 ms 20936 KB Output is correct
98 Correct 120 ms 20936 KB Output is correct
99 Correct 57 ms 20936 KB Output is correct
100 Correct 61 ms 20932 KB Output is correct
101 Correct 41 ms 17332 KB Output is correct
102 Correct 37 ms 17252 KB Output is correct
103 Correct 44 ms 16844 KB Output is correct
104 Correct 39 ms 16844 KB Output is correct
105 Correct 137 ms 22820 KB Output is correct
106 Correct 145 ms 22840 KB Output is correct
107 Correct 158 ms 27644 KB Output is correct
108 Correct 137 ms 27836 KB Output is correct
109 Correct 73 ms 20120 KB Output is correct
110 Correct 72 ms 20116 KB Output is correct
111 Correct 80 ms 18684 KB Output is correct
112 Correct 91 ms 18664 KB Output is correct