Submission #1057501

# Submission time Handle Problem Language Result Execution time Memory
1057501 2024-08-13T20:45:23 Z sammyuri Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
352 ms 42648 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5 + 5;

const ll INF = 1e18;
int n;
vector<pair<int, ll>> adj[MAXN];

void dijkstra(int startnode, vector<ll> &dist) {
    dist.clear(); dist.resize(n, INF);
    dist[startnode] = 0;
    priority_queue<pair<ll, int>> pq;
    pq.push({0, startnode});
    while (pq.size()) {
        pair<ll, int> cur = pq.top(); pq.pop();
        ll curdist = -cur.first;
        int curnode = cur.second;
        if (dist[curnode] != curdist)
            continue;
        for (auto a : adj[curnode]) {
            ll newdist = curdist + a.second;
            if (dist[a.first] > newdist) {
                dist[a.first] = newdist;
                pq.push({-newdist, a.first});
            }
        }
    }
}

int main() {
    int m; cin >> n >> m;
    int s, t; ll l, k; cin >> s >> t >> l >> k;
    s --; t --;
    while (m --) {
        int a, b; ll c; cin >> a >> b >> c;
        a --; b --;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    vector<ll> dist_forwards, dist_backwards;
    dijkstra(s, dist_forwards);
    dijkstra(t, dist_backwards);
    if (dist_forwards[t] <= k) {
        cout << (ll)(n * (ll)(n - 1)) / 2; return 0;
    }
    ll ans = 0;
    ordered_set vals;
    for (int i = 0; i < n; i ++)
        vals.insert({dist_backwards[i], i});
    vector<pair<ll, int>> ee;
    for (int i = 0; i < n; i ++)
        ee.push_back({dist_forwards[i], i});
    sort(ee.begin(), ee.end());
    for (int ii = 0; ii < n; ii ++) {
        int i = ee[ii].second;
        vals.erase({dist_backwards[i], i});
        ll sofar = dist_forwards[i] + l;
        ll req = k - sofar;
        // cout << dist_backwards[i] << " " << sofar << " " <<  vals.order_of_key({req, 1e9}) << endl;
        ll cur = vals.order_of_key({req, 1e9});
        ans += cur;
    }
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 160 ms 38324 KB Output is correct
8 Correct 159 ms 37200 KB Output is correct
9 Correct 88 ms 22708 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 5468 KB Output is correct
13 Correct 3 ms 5468 KB Output is correct
14 Correct 176 ms 33048 KB Output is correct
15 Correct 239 ms 40188 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 235 ms 38708 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 5480 KB Output is correct
22 Correct 4 ms 5464 KB Output is correct
23 Correct 171 ms 32444 KB Output is correct
24 Correct 248 ms 39684 KB Output is correct
25 Correct 1 ms 4952 KB Output is correct
26 Correct 2 ms 5404 KB Output is correct
27 Correct 109 ms 28600 KB Output is correct
28 Correct 163 ms 26656 KB Output is correct
29 Correct 163 ms 31428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4952 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4956 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4952 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4956 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
33 Correct 3 ms 5468 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5468 KB Output is correct
36 Correct 3 ms 5472 KB Output is correct
37 Correct 2 ms 5724 KB Output is correct
38 Correct 2 ms 5464 KB Output is correct
39 Correct 4 ms 5468 KB Output is correct
40 Correct 2 ms 5468 KB Output is correct
41 Correct 2 ms 5212 KB Output is correct
42 Correct 3 ms 5468 KB Output is correct
43 Correct 4 ms 5468 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 4 ms 5464 KB Output is correct
46 Correct 4 ms 5468 KB Output is correct
47 Correct 3 ms 5468 KB Output is correct
48 Correct 3 ms 5468 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 3 ms 5464 KB Output is correct
51 Correct 4 ms 5464 KB Output is correct
52 Correct 3 ms 5532 KB Output is correct
53 Correct 3 ms 5468 KB Output is correct
54 Correct 3 ms 5468 KB Output is correct
55 Correct 3 ms 5468 KB Output is correct
56 Correct 3 ms 5464 KB Output is correct
57 Correct 2 ms 5468 KB Output is correct
58 Correct 3 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 160 ms 38324 KB Output is correct
8 Correct 159 ms 37200 KB Output is correct
9 Correct 88 ms 22708 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 5468 KB Output is correct
13 Correct 3 ms 5468 KB Output is correct
14 Correct 176 ms 33048 KB Output is correct
15 Correct 239 ms 40188 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 235 ms 38708 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 5480 KB Output is correct
22 Correct 4 ms 5464 KB Output is correct
23 Correct 171 ms 32444 KB Output is correct
24 Correct 248 ms 39684 KB Output is correct
25 Correct 1 ms 4952 KB Output is correct
26 Correct 2 ms 5404 KB Output is correct
27 Correct 109 ms 28600 KB Output is correct
28 Correct 163 ms 26656 KB Output is correct
29 Correct 163 ms 31428 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4952 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 1 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 1 ms 4956 KB Output is correct
40 Correct 1 ms 4956 KB Output is correct
41 Correct 1 ms 4956 KB Output is correct
42 Correct 1 ms 4956 KB Output is correct
43 Correct 1 ms 4956 KB Output is correct
44 Correct 1 ms 4952 KB Output is correct
45 Correct 1 ms 4956 KB Output is correct
46 Correct 1 ms 4956 KB Output is correct
47 Correct 1 ms 4956 KB Output is correct
48 Correct 1 ms 4956 KB Output is correct
49 Correct 1 ms 4956 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 1 ms 4952 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Correct 1 ms 4956 KB Output is correct
54 Correct 1 ms 4956 KB Output is correct
55 Correct 1 ms 4956 KB Output is correct
56 Correct 1 ms 4956 KB Output is correct
57 Correct 1 ms 4956 KB Output is correct
58 Correct 1 ms 4956 KB Output is correct
59 Correct 1 ms 4956 KB Output is correct
60 Correct 1 ms 4956 KB Output is correct
61 Correct 1 ms 4956 KB Output is correct
62 Correct 3 ms 5468 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 2 ms 5468 KB Output is correct
65 Correct 3 ms 5472 KB Output is correct
66 Correct 2 ms 5724 KB Output is correct
67 Correct 2 ms 5464 KB Output is correct
68 Correct 4 ms 5468 KB Output is correct
69 Correct 2 ms 5468 KB Output is correct
70 Correct 2 ms 5212 KB Output is correct
71 Correct 3 ms 5468 KB Output is correct
72 Correct 4 ms 5468 KB Output is correct
73 Correct 3 ms 5468 KB Output is correct
74 Correct 4 ms 5464 KB Output is correct
75 Correct 4 ms 5468 KB Output is correct
76 Correct 3 ms 5468 KB Output is correct
77 Correct 3 ms 5468 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 3 ms 5464 KB Output is correct
80 Correct 4 ms 5464 KB Output is correct
81 Correct 3 ms 5532 KB Output is correct
82 Correct 3 ms 5468 KB Output is correct
83 Correct 3 ms 5468 KB Output is correct
84 Correct 3 ms 5468 KB Output is correct
85 Correct 3 ms 5464 KB Output is correct
86 Correct 2 ms 5468 KB Output is correct
87 Correct 3 ms 5468 KB Output is correct
88 Correct 136 ms 23672 KB Output is correct
89 Correct 137 ms 23584 KB Output is correct
90 Correct 258 ms 41380 KB Output is correct
91 Correct 93 ms 18948 KB Output is correct
92 Correct 86 ms 18788 KB Output is correct
93 Correct 199 ms 34496 KB Output is correct
94 Correct 201 ms 33224 KB Output is correct
95 Correct 307 ms 41640 KB Output is correct
96 Correct 163 ms 24636 KB Output is correct
97 Correct 299 ms 41212 KB Output is correct
98 Correct 259 ms 41664 KB Output is correct
99 Correct 260 ms 39108 KB Output is correct
100 Correct 228 ms 40136 KB Output is correct
101 Correct 84 ms 18772 KB Output is correct
102 Correct 84 ms 18652 KB Output is correct
103 Correct 198 ms 32452 KB Output is correct
104 Correct 210 ms 33940 KB Output is correct
105 Correct 321 ms 40360 KB Output is correct
106 Correct 352 ms 40112 KB Output is correct
107 Correct 270 ms 41644 KB Output is correct
108 Correct 266 ms 42648 KB Output is correct
109 Correct 159 ms 27800 KB Output is correct
110 Correct 164 ms 27876 KB Output is correct
111 Correct 168 ms 32164 KB Output is correct
112 Correct 169 ms 32428 KB Output is correct