Submission #1112298

# Submission time Handle Problem Language Result Execution time Memory
1112298 2024-11-14T03:06:49 Z Mike_Vu Construction Project 2 (JOI24_ho_t2) C++14
100 / 100
199 ms 24584 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double dou;
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define MASK(x) (1LL<<(x))
#define BITj(x, j) (((x)>>(j))&1)

template<typename T> bool maximize(T &x, const T &y) {
    if (x < y) {x = y; return 1;}
    return 0;
}
template<typename T> bool minimize(T &x, const T &y) {
    if (x > y) {x = y; return 1;}
    return 0;
}

const int maxn = 2e5+5;
int n, m, s, t;
ll len, bound, ans = 0;
vector<pii> a[maxn];
ll dis1[maxn], dis2[maxn];

void dijkstra(int s, ll dis[]) {
    priority_queue<pair<ll, int>> q;
    q.push({0, s});
    dis[s] = 0;
    while (!q.empty()) {
        int u = q.top().se;
        ll w = -q.top().fi;
        q.pop();
        if (w != dis[u]) continue;
        for (int i = 0; i < (int)a[u].size(); i++) {
            int v = a[u][i].fi, w = a[u][i].se;
            if (minimize(dis[v], dis[u]+w)) {
                q.push({-dis[v], v});
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    #define name "task"
//    if (fopen(name".inp", "r")) {
//        freopen(name".inp", "r", stdin);
//        freopen(name".out", "w", stdout);
//    }
    cin >> n >> m >> s >> t >> len >> bound;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        a[u].pb({v, w});
        a[v].pb({u, w});
    }
    //dijkstra
    memset(dis1, 0x3f, sizeof(dis1));
    dijkstra(s, dis1);
    memset(dis2, 0x3f, sizeof(dis2));
    dijkstra(t, dis2);
    //check case 1
    if (dis1[t] <= bound) {
        cout << ((ll)n*(n-1)/2);
        return 0;
    }
    //cal + bs
    vector<pair<ll, int>> val;
    for (int i = 1; i <= n; i++) {
        val.pb({dis1[i], i});
    }
    sort(val.begin(), val.end());
    for (int i = 1; i < n; i++) {
        int u = val[i].se;
        //binsearch with bound
        ll curbound = bound-len-dis2[u];
        if (curbound < 0) continue;
        int k = -1;
        for (int j = n>>1; j; j >>= 1) {
            while (k+j < n && val[k+j].fi <= curbound) k += j;
        }
        ans += k+1;
    }
    //output
    cout << ans;
}
/*
7 8
6 7 1 2
1 2 1
1 6 1
2 3 1
2 4 1
3 5 1
3 7 1
4 5 1
5 6 1

3 2
1 3 1 2
1 2 1
2 3 1

6 4
2 5 1000000000 1
1 2 1000000000
2 3 1000000000
2 4 1000000000
5 6 1000000000

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
*/

# Verdict Execution time Memory Grader output
1 Correct 3 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 3 ms 8272 KB Output is correct
4 Correct 3 ms 8440 KB Output is correct
5 Correct 4 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 68 ms 22616 KB Output is correct
8 Correct 99 ms 22688 KB Output is correct
9 Correct 67 ms 20660 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 3 ms 8272 KB Output is correct
12 Correct 3 ms 8440 KB Output is correct
13 Correct 4 ms 8272 KB Output is correct
14 Correct 44 ms 18624 KB Output is correct
15 Correct 139 ms 21524 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 71 ms 20624 KB Output is correct
19 Correct 3 ms 8272 KB Output is correct
20 Correct 2 ms 8040 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 5 ms 8272 KB Output is correct
23 Correct 41 ms 18624 KB Output is correct
24 Correct 122 ms 21344 KB Output is correct
25 Correct 2 ms 8272 KB Output is correct
26 Correct 3 ms 8272 KB Output is correct
27 Correct 76 ms 24456 KB Output is correct
28 Correct 66 ms 16544 KB Output is correct
29 Correct 51 ms 19640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 2 ms 8272 KB Output is correct
4 Correct 2 ms 8272 KB Output is correct
5 Correct 3 ms 8440 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 2 ms 8272 KB Output is correct
8 Correct 3 ms 8272 KB Output is correct
9 Correct 2 ms 8272 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 2 ms 8272 KB Output is correct
12 Correct 3 ms 8272 KB Output is correct
13 Correct 2 ms 8272 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 2 ms 8272 KB Output is correct
16 Correct 4 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 3 ms 8272 KB Output is correct
19 Correct 3 ms 8272 KB Output is correct
20 Correct 3 ms 8272 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 3 ms 8272 KB Output is correct
23 Correct 3 ms 8120 KB Output is correct
24 Correct 3 ms 8272 KB Output is correct
25 Correct 3 ms 8272 KB Output is correct
26 Correct 3 ms 8288 KB Output is correct
27 Correct 3 ms 8272 KB Output is correct
28 Correct 3 ms 8272 KB Output is correct
29 Correct 3 ms 8272 KB Output is correct
30 Correct 3 ms 8272 KB Output is correct
31 Correct 3 ms 8272 KB Output is correct
32 Correct 3 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 2 ms 8272 KB Output is correct
4 Correct 2 ms 8272 KB Output is correct
5 Correct 3 ms 8440 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 2 ms 8272 KB Output is correct
8 Correct 3 ms 8272 KB Output is correct
9 Correct 2 ms 8272 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 2 ms 8272 KB Output is correct
12 Correct 3 ms 8272 KB Output is correct
13 Correct 2 ms 8272 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 2 ms 8272 KB Output is correct
16 Correct 4 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 3 ms 8272 KB Output is correct
19 Correct 3 ms 8272 KB Output is correct
20 Correct 3 ms 8272 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 3 ms 8272 KB Output is correct
23 Correct 3 ms 8120 KB Output is correct
24 Correct 3 ms 8272 KB Output is correct
25 Correct 3 ms 8272 KB Output is correct
26 Correct 3 ms 8288 KB Output is correct
27 Correct 3 ms 8272 KB Output is correct
28 Correct 3 ms 8272 KB Output is correct
29 Correct 3 ms 8272 KB Output is correct
30 Correct 3 ms 8272 KB Output is correct
31 Correct 3 ms 8272 KB Output is correct
32 Correct 3 ms 8272 KB Output is correct
33 Correct 5 ms 8272 KB Output is correct
34 Correct 4 ms 8272 KB Output is correct
35 Correct 3 ms 8272 KB Output is correct
36 Correct 5 ms 8272 KB Output is correct
37 Correct 3 ms 8272 KB Output is correct
38 Correct 3 ms 8272 KB Output is correct
39 Correct 5 ms 8272 KB Output is correct
40 Correct 4 ms 8272 KB Output is correct
41 Correct 3 ms 8272 KB Output is correct
42 Correct 3 ms 8272 KB Output is correct
43 Correct 4 ms 8376 KB Output is correct
44 Correct 5 ms 8272 KB Output is correct
45 Correct 4 ms 8396 KB Output is correct
46 Correct 4 ms 8272 KB Output is correct
47 Correct 4 ms 8272 KB Output is correct
48 Correct 4 ms 8272 KB Output is correct
49 Correct 3 ms 8272 KB Output is correct
50 Correct 3 ms 8272 KB Output is correct
51 Correct 4 ms 8272 KB Output is correct
52 Correct 4 ms 8272 KB Output is correct
53 Correct 4 ms 8272 KB Output is correct
54 Correct 5 ms 8272 KB Output is correct
55 Correct 4 ms 8272 KB Output is correct
56 Correct 4 ms 8272 KB Output is correct
57 Correct 4 ms 8272 KB Output is correct
58 Correct 3 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 3 ms 8272 KB Output is correct
4 Correct 3 ms 8440 KB Output is correct
5 Correct 4 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 68 ms 22616 KB Output is correct
8 Correct 99 ms 22688 KB Output is correct
9 Correct 67 ms 20660 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 3 ms 8272 KB Output is correct
12 Correct 3 ms 8440 KB Output is correct
13 Correct 4 ms 8272 KB Output is correct
14 Correct 44 ms 18624 KB Output is correct
15 Correct 139 ms 21524 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 71 ms 20624 KB Output is correct
19 Correct 3 ms 8272 KB Output is correct
20 Correct 2 ms 8040 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 5 ms 8272 KB Output is correct
23 Correct 41 ms 18624 KB Output is correct
24 Correct 122 ms 21344 KB Output is correct
25 Correct 2 ms 8272 KB Output is correct
26 Correct 3 ms 8272 KB Output is correct
27 Correct 76 ms 24456 KB Output is correct
28 Correct 66 ms 16544 KB Output is correct
29 Correct 51 ms 19640 KB Output is correct
30 Correct 2 ms 8272 KB Output is correct
31 Correct 2 ms 8272 KB Output is correct
32 Correct 2 ms 8272 KB Output is correct
33 Correct 2 ms 8272 KB Output is correct
34 Correct 3 ms 8440 KB Output is correct
35 Correct 4 ms 8284 KB Output is correct
36 Correct 2 ms 8272 KB Output is correct
37 Correct 3 ms 8272 KB Output is correct
38 Correct 2 ms 8272 KB Output is correct
39 Correct 3 ms 8272 KB Output is correct
40 Correct 2 ms 8272 KB Output is correct
41 Correct 3 ms 8272 KB Output is correct
42 Correct 2 ms 8272 KB Output is correct
43 Correct 2 ms 8272 KB Output is correct
44 Correct 2 ms 8272 KB Output is correct
45 Correct 4 ms 8272 KB Output is correct
46 Correct 3 ms 8272 KB Output is correct
47 Correct 3 ms 8272 KB Output is correct
48 Correct 3 ms 8272 KB Output is correct
49 Correct 3 ms 8272 KB Output is correct
50 Correct 3 ms 8272 KB Output is correct
51 Correct 3 ms 8272 KB Output is correct
52 Correct 3 ms 8120 KB Output is correct
53 Correct 3 ms 8272 KB Output is correct
54 Correct 3 ms 8272 KB Output is correct
55 Correct 3 ms 8288 KB Output is correct
56 Correct 3 ms 8272 KB Output is correct
57 Correct 3 ms 8272 KB Output is correct
58 Correct 3 ms 8272 KB Output is correct
59 Correct 3 ms 8272 KB Output is correct
60 Correct 3 ms 8272 KB Output is correct
61 Correct 3 ms 8272 KB Output is correct
62 Correct 5 ms 8272 KB Output is correct
63 Correct 4 ms 8272 KB Output is correct
64 Correct 3 ms 8272 KB Output is correct
65 Correct 5 ms 8272 KB Output is correct
66 Correct 3 ms 8272 KB Output is correct
67 Correct 3 ms 8272 KB Output is correct
68 Correct 5 ms 8272 KB Output is correct
69 Correct 4 ms 8272 KB Output is correct
70 Correct 3 ms 8272 KB Output is correct
71 Correct 3 ms 8272 KB Output is correct
72 Correct 4 ms 8376 KB Output is correct
73 Correct 5 ms 8272 KB Output is correct
74 Correct 4 ms 8396 KB Output is correct
75 Correct 4 ms 8272 KB Output is correct
76 Correct 4 ms 8272 KB Output is correct
77 Correct 4 ms 8272 KB Output is correct
78 Correct 3 ms 8272 KB Output is correct
79 Correct 3 ms 8272 KB Output is correct
80 Correct 4 ms 8272 KB Output is correct
81 Correct 4 ms 8272 KB Output is correct
82 Correct 4 ms 8272 KB Output is correct
83 Correct 5 ms 8272 KB Output is correct
84 Correct 4 ms 8272 KB Output is correct
85 Correct 4 ms 8272 KB Output is correct
86 Correct 4 ms 8272 KB Output is correct
87 Correct 3 ms 8272 KB Output is correct
88 Correct 85 ms 15716 KB Output is correct
89 Correct 89 ms 15488 KB Output is correct
90 Correct 88 ms 21404 KB Output is correct
91 Correct 39 ms 13952 KB Output is correct
92 Correct 41 ms 13896 KB Output is correct
93 Correct 47 ms 18624 KB Output is correct
94 Correct 50 ms 18620 KB Output is correct
95 Correct 154 ms 21420 KB Output is correct
96 Correct 136 ms 16796 KB Output is correct
97 Correct 143 ms 20664 KB Output is correct
98 Correct 139 ms 20700 KB Output is correct
99 Correct 74 ms 20664 KB Output is correct
100 Correct 68 ms 20676 KB Output is correct
101 Correct 49 ms 13772 KB Output is correct
102 Correct 42 ms 14016 KB Output is correct
103 Correct 44 ms 18632 KB Output is correct
104 Correct 50 ms 18620 KB Output is correct
105 Correct 138 ms 21424 KB Output is correct
106 Correct 157 ms 21432 KB Output is correct
107 Correct 184 ms 24584 KB Output is correct
108 Correct 199 ms 24204 KB Output is correct
109 Correct 81 ms 16556 KB Output is correct
110 Correct 75 ms 16600 KB Output is correct
111 Correct 87 ms 19700 KB Output is correct
112 Correct 95 ms 19672 KB Output is correct