Submission #1057342

# Submission time Handle Problem Language Result Execution time Memory
1057342 2024-08-13T17:40:21 Z beaconmc Construction Project 2 (JOI24_ho_t2) C++14
100 / 100
215 ms 38832 KB
#include <bits/stdc++.h>
 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;

const ll maxn = 200005;
const ll INF = 10000000000000000;
vector<array<ll, 2>> edges[maxn];
ll dists[maxn];
ll distt[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	FOR(i,0,maxn) dists[i] = INF, distt[i] = INF;

	ll n,m;
	cin >> n >> m;
	ll s, t, l, k;
	cin >> s >> t >> l >> k;
	FOR(i,0,m){
		ll a,b,c;
		cin >> a >> b >> c;

		edges[a].push_back({b,c});
		edges[b].push_back({a,c});
	}

	priority_queue<vector<ll>> pq;
	dists[s] = 0;
	pq.push({0, s});

	while (pq.size()){
		vector<ll> node = pq.top(); pq.pop();

		node[0] = -node[0];
		if (dists[node[1]] != node[0]) continue;

		for (auto&i : edges[node[1]]){
			if (dists[i[0]] > dists[node[1]] + i[1]){
				dists[i[0]] = dists[node[1]] + i[1];
				pq.push({-dists[i[0]] , i[0]});
			}
		}
	}
	distt[t] = 0;
	pq.push({0, t});

	while (pq.size()){
		vector<ll> node = pq.top(); pq.pop();

		node[0] = -node[0];
		if (distt[node[1]] != node[0]) continue;

		for (auto&i : edges[node[1]]){
			if (distt[i[0]] > distt[node[1]] + i[1]){
				distt[i[0]] = distt[node[1]] + i[1];
				pq.push({-distt[i[0]] , i[0]});
			}
		}
	}

	if (dists[t] <= k) cout << n * (n-1) / 2;
	else{
		ll ans = 0;
		vector<ll> S, T;
		FOR(i,1,n+1) S.push_back(dists[i]), T.push_back(distt[i]);
		sort(S.begin(), S.end());
		sort(T.begin(), T.end());


		FOR(i,0,n){
			ll req = k - (S[i]+l);
			ll sus = upper_bound(T.begin(), T.end(), req) - T.begin();
			ans += sus;
		}

		cout << ans << endl;

	}




}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 1 ms 8284 KB Output is correct
4 Correct 1 ms 8284 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 63 ms 28508 KB Output is correct
8 Correct 86 ms 27704 KB Output is correct
9 Correct 80 ms 28720 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 1 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 3 ms 8496 KB Output is correct
14 Correct 34 ms 18132 KB Output is correct
15 Correct 169 ms 26172 KB Output is correct
16 Correct 2 ms 8280 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 74 ms 23896 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8056 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 3 ms 8540 KB Output is correct
23 Correct 33 ms 18236 KB Output is correct
24 Correct 153 ms 26056 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 96 ms 32588 KB Output is correct
28 Correct 66 ms 25384 KB Output is correct
29 Correct 56 ms 22468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 1 ms 8284 KB Output is correct
4 Correct 1 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 1 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 1 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8280 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8280 KB Output is correct
14 Correct 1 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 1 ms 8284 KB Output is correct
17 Correct 1 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 1 ms 8284 KB Output is correct
22 Correct 1 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8120 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8284 KB Output is correct
27 Correct 1 ms 8284 KB Output is correct
28 Correct 1 ms 8284 KB Output is correct
29 Correct 1 ms 8280 KB Output is correct
30 Correct 1 ms 8140 KB Output is correct
31 Correct 2 ms 8284 KB Output is correct
32 Correct 1 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 1 ms 8284 KB Output is correct
4 Correct 1 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 1 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 1 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8280 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8280 KB Output is correct
14 Correct 1 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 1 ms 8284 KB Output is correct
17 Correct 1 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 1 ms 8284 KB Output is correct
22 Correct 1 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8120 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8284 KB Output is correct
27 Correct 1 ms 8284 KB Output is correct
28 Correct 1 ms 8284 KB Output is correct
29 Correct 1 ms 8280 KB Output is correct
30 Correct 1 ms 8140 KB Output is correct
31 Correct 2 ms 8284 KB Output is correct
32 Correct 1 ms 8284 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8296 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 3 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 3 ms 8284 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8540 KB Output is correct
45 Correct 4 ms 8540 KB Output is correct
46 Correct 3 ms 8556 KB Output is correct
47 Correct 2 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 3 ms 8540 KB Output is correct
50 Correct 2 ms 8284 KB Output is correct
51 Correct 3 ms 8540 KB Output is correct
52 Correct 3 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
55 Correct 3 ms 8540 KB Output is correct
56 Correct 3 ms 8540 KB Output is correct
57 Correct 3 ms 8540 KB Output is correct
58 Correct 3 ms 8464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 1 ms 8284 KB Output is correct
4 Correct 1 ms 8284 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 63 ms 28508 KB Output is correct
8 Correct 86 ms 27704 KB Output is correct
9 Correct 80 ms 28720 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 1 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 3 ms 8496 KB Output is correct
14 Correct 34 ms 18132 KB Output is correct
15 Correct 169 ms 26172 KB Output is correct
16 Correct 2 ms 8280 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 74 ms 23896 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8056 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 3 ms 8540 KB Output is correct
23 Correct 33 ms 18236 KB Output is correct
24 Correct 153 ms 26056 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 96 ms 32588 KB Output is correct
28 Correct 66 ms 25384 KB Output is correct
29 Correct 56 ms 22468 KB Output is correct
30 Correct 2 ms 8028 KB Output is correct
31 Correct 1 ms 8284 KB Output is correct
32 Correct 1 ms 8284 KB Output is correct
33 Correct 1 ms 8284 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 1 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 1 ms 8284 KB Output is correct
39 Correct 2 ms 8284 KB Output is correct
40 Correct 2 ms 8280 KB Output is correct
41 Correct 2 ms 8284 KB Output is correct
42 Correct 2 ms 8280 KB Output is correct
43 Correct 1 ms 8284 KB Output is correct
44 Correct 2 ms 8284 KB Output is correct
45 Correct 1 ms 8284 KB Output is correct
46 Correct 1 ms 8284 KB Output is correct
47 Correct 2 ms 8284 KB Output is correct
48 Correct 2 ms 8284 KB Output is correct
49 Correct 2 ms 8284 KB Output is correct
50 Correct 1 ms 8284 KB Output is correct
51 Correct 1 ms 8284 KB Output is correct
52 Correct 2 ms 8284 KB Output is correct
53 Correct 2 ms 8120 KB Output is correct
54 Correct 2 ms 8284 KB Output is correct
55 Correct 2 ms 8284 KB Output is correct
56 Correct 1 ms 8284 KB Output is correct
57 Correct 1 ms 8284 KB Output is correct
58 Correct 1 ms 8280 KB Output is correct
59 Correct 1 ms 8140 KB Output is correct
60 Correct 2 ms 8284 KB Output is correct
61 Correct 1 ms 8284 KB Output is correct
62 Correct 3 ms 8540 KB Output is correct
63 Correct 2 ms 8540 KB Output is correct
64 Correct 2 ms 8296 KB Output is correct
65 Correct 3 ms 8540 KB Output is correct
66 Correct 2 ms 8540 KB Output is correct
67 Correct 2 ms 8284 KB Output is correct
68 Correct 3 ms 8540 KB Output is correct
69 Correct 3 ms 8540 KB Output is correct
70 Correct 2 ms 8540 KB Output is correct
71 Correct 3 ms 8284 KB Output is correct
72 Correct 3 ms 8540 KB Output is correct
73 Correct 3 ms 8540 KB Output is correct
74 Correct 4 ms 8540 KB Output is correct
75 Correct 3 ms 8556 KB Output is correct
76 Correct 2 ms 8540 KB Output is correct
77 Correct 2 ms 8540 KB Output is correct
78 Correct 3 ms 8540 KB Output is correct
79 Correct 2 ms 8284 KB Output is correct
80 Correct 3 ms 8540 KB Output is correct
81 Correct 3 ms 8540 KB Output is correct
82 Correct 3 ms 8540 KB Output is correct
83 Correct 3 ms 8540 KB Output is correct
84 Correct 3 ms 8540 KB Output is correct
85 Correct 3 ms 8540 KB Output is correct
86 Correct 3 ms 8540 KB Output is correct
87 Correct 3 ms 8464 KB Output is correct
88 Correct 87 ms 23800 KB Output is correct
89 Correct 96 ms 23868 KB Output is correct
90 Correct 84 ms 26976 KB Output is correct
91 Correct 35 ms 22108 KB Output is correct
92 Correct 36 ms 22056 KB Output is correct
93 Correct 37 ms 18976 KB Output is correct
94 Correct 59 ms 19116 KB Output is correct
95 Correct 182 ms 29120 KB Output is correct
96 Correct 148 ms 25292 KB Output is correct
97 Correct 135 ms 26304 KB Output is correct
98 Correct 118 ms 26304 KB Output is correct
99 Correct 64 ms 25288 KB Output is correct
100 Correct 65 ms 25280 KB Output is correct
101 Correct 32 ms 22100 KB Output is correct
102 Correct 33 ms 22100 KB Output is correct
103 Correct 35 ms 19064 KB Output is correct
104 Correct 37 ms 19124 KB Output is correct
105 Correct 172 ms 29116 KB Output is correct
106 Correct 199 ms 29120 KB Output is correct
107 Correct 203 ms 37552 KB Output is correct
108 Correct 215 ms 38832 KB Output is correct
109 Correct 84 ms 25908 KB Output is correct
110 Correct 82 ms 25892 KB Output is correct
111 Correct 110 ms 24836 KB Output is correct
112 Correct 120 ms 24992 KB Output is correct