답안 #1101261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101261 2024-10-16T01:11:41 Z thangdz2k7 Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
160 ms 25908 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using li = pair <ll, int>;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, m, s, t, l;
ll k, d[2][N];
vector <ii> adj[N];

priority_queue <li> qu;
const ll inf = 1e18;

void dij(ll *d){
    for (int i = 1; i <= n; ++ i) d[i] ^= inf;
    while (qu.size()){
        auto [du, u] = qu.top(); qu.pop(); du = -du;
        if (du != d[u]) continue;
        for (auto [w, v] : adj[u]){
            if (d[v] > d[u] + w){
                d[v] = d[u] + w;
                qu.push({-d[v], v});
            }
        }
    }
}

void solve(){
    cin >> n >> m;
    cin >> s >> t >> l >> k;
    for (int i = 1, a, b, c; i <= m; ++ i){
        cin >> a >> b >> c;
        adj[a].emplace_back(c, b);
        adj[b].emplace_back(c, a);
    }

    d[0][s] = inf;
    qu.push({0, s});
    dij(d[0]);

    d[1][t] = inf;
    qu.push({0, t});
    dij(d[1]);

    if (d[0][t] <= k){
        cout << ll(n - 1) * n / 2;
        return;
    }

    for (int op : {0, 1}) sort(d[op] + 1, d[op] + n + 1);
    int v = 0; ll ans = 0;
    for (int u = n; u >= 1; -- u){
        while (v < n && d[0][u] + d[1][v + 1] <= k - l) ++ v;
        ans += v;
    }

    cout << ans;
}

int main(){
    if (fopen("solve.inp", "r")){
        freopen("solve.inp", "r", stdin);
        freopen("solve.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

Main.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
Main.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
Main.cpp:20:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
Main.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
Main.cpp: In function 'int main()':
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen("solve.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen("solve.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 1 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6796 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 3 ms 6992 KB Output is correct
7 Correct 57 ms 18864 KB Output is correct
8 Correct 82 ms 19124 KB Output is correct
9 Correct 69 ms 21688 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 3 ms 6736 KB Output is correct
14 Correct 32 ms 13904 KB Output is correct
15 Correct 116 ms 18768 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 82 ms 17324 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 32 ms 13832 KB Output is correct
24 Correct 124 ms 18692 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 3 ms 6992 KB Output is correct
27 Correct 74 ms 24412 KB Output is correct
28 Correct 53 ms 17072 KB Output is correct
29 Correct 54 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 1 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 1 ms 6736 KB Output is correct
6 Correct 1 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6572 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 1 ms 6736 KB Output is correct
12 Correct 1 ms 6736 KB Output is correct
13 Correct 2 ms 6904 KB Output is correct
14 Correct 1 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 1 ms 6736 KB Output is correct
21 Correct 1 ms 6736 KB Output is correct
22 Correct 2 ms 6736 KB Output is correct
23 Correct 1 ms 6752 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 2 ms 6580 KB Output is correct
26 Correct 1 ms 6736 KB Output is correct
27 Correct 2 ms 6736 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 1 ms 6736 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 1 ms 6736 KB Output is correct
32 Correct 1 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 1 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 1 ms 6736 KB Output is correct
6 Correct 1 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6572 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 1 ms 6736 KB Output is correct
12 Correct 1 ms 6736 KB Output is correct
13 Correct 2 ms 6904 KB Output is correct
14 Correct 1 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 1 ms 6736 KB Output is correct
21 Correct 1 ms 6736 KB Output is correct
22 Correct 2 ms 6736 KB Output is correct
23 Correct 1 ms 6752 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 2 ms 6580 KB Output is correct
26 Correct 1 ms 6736 KB Output is correct
27 Correct 2 ms 6736 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 1 ms 6736 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 1 ms 6736 KB Output is correct
32 Correct 1 ms 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 3 ms 6992 KB Output is correct
35 Correct 2 ms 6736 KB Output is correct
36 Correct 3 ms 6736 KB Output is correct
37 Correct 3 ms 6736 KB Output is correct
38 Correct 2 ms 6904 KB Output is correct
39 Correct 3 ms 6736 KB Output is correct
40 Correct 3 ms 6992 KB Output is correct
41 Correct 2 ms 6736 KB Output is correct
42 Correct 2 ms 6736 KB Output is correct
43 Correct 3 ms 6736 KB Output is correct
44 Correct 3 ms 6992 KB Output is correct
45 Correct 3 ms 6736 KB Output is correct
46 Correct 3 ms 6904 KB Output is correct
47 Correct 3 ms 6736 KB Output is correct
48 Correct 2 ms 6760 KB Output is correct
49 Correct 2 ms 6736 KB Output is correct
50 Correct 2 ms 6736 KB Output is correct
51 Correct 3 ms 7160 KB Output is correct
52 Correct 3 ms 6816 KB Output is correct
53 Correct 3 ms 6992 KB Output is correct
54 Correct 3 ms 6992 KB Output is correct
55 Correct 4 ms 6772 KB Output is correct
56 Correct 3 ms 6736 KB Output is correct
57 Correct 3 ms 6904 KB Output is correct
58 Correct 2 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 1 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6796 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 3 ms 6992 KB Output is correct
7 Correct 57 ms 18864 KB Output is correct
8 Correct 82 ms 19124 KB Output is correct
9 Correct 69 ms 21688 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 3 ms 6736 KB Output is correct
14 Correct 32 ms 13904 KB Output is correct
15 Correct 116 ms 18768 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 82 ms 17324 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 32 ms 13832 KB Output is correct
24 Correct 124 ms 18692 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 3 ms 6992 KB Output is correct
27 Correct 74 ms 24412 KB Output is correct
28 Correct 53 ms 17072 KB Output is correct
29 Correct 54 ms 15696 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 1 ms 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 1 ms 6736 KB Output is correct
35 Correct 1 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 2 ms 6572 KB Output is correct
38 Correct 2 ms 6736 KB Output is correct
39 Correct 1 ms 6736 KB Output is correct
40 Correct 1 ms 6736 KB Output is correct
41 Correct 1 ms 6736 KB Output is correct
42 Correct 2 ms 6904 KB Output is correct
43 Correct 1 ms 6736 KB Output is correct
44 Correct 2 ms 6736 KB Output is correct
45 Correct 2 ms 6736 KB Output is correct
46 Correct 2 ms 6736 KB Output is correct
47 Correct 2 ms 6736 KB Output is correct
48 Correct 2 ms 6736 KB Output is correct
49 Correct 1 ms 6736 KB Output is correct
50 Correct 1 ms 6736 KB Output is correct
51 Correct 2 ms 6736 KB Output is correct
52 Correct 1 ms 6752 KB Output is correct
53 Correct 2 ms 6736 KB Output is correct
54 Correct 2 ms 6580 KB Output is correct
55 Correct 1 ms 6736 KB Output is correct
56 Correct 2 ms 6736 KB Output is correct
57 Correct 2 ms 6736 KB Output is correct
58 Correct 1 ms 6736 KB Output is correct
59 Correct 2 ms 6736 KB Output is correct
60 Correct 1 ms 6736 KB Output is correct
61 Correct 1 ms 6736 KB Output is correct
62 Correct 2 ms 6736 KB Output is correct
63 Correct 3 ms 6992 KB Output is correct
64 Correct 2 ms 6736 KB Output is correct
65 Correct 3 ms 6736 KB Output is correct
66 Correct 3 ms 6736 KB Output is correct
67 Correct 2 ms 6904 KB Output is correct
68 Correct 3 ms 6736 KB Output is correct
69 Correct 3 ms 6992 KB Output is correct
70 Correct 2 ms 6736 KB Output is correct
71 Correct 2 ms 6736 KB Output is correct
72 Correct 3 ms 6736 KB Output is correct
73 Correct 3 ms 6992 KB Output is correct
74 Correct 3 ms 6736 KB Output is correct
75 Correct 3 ms 6904 KB Output is correct
76 Correct 3 ms 6736 KB Output is correct
77 Correct 2 ms 6760 KB Output is correct
78 Correct 2 ms 6736 KB Output is correct
79 Correct 2 ms 6736 KB Output is correct
80 Correct 3 ms 7160 KB Output is correct
81 Correct 3 ms 6816 KB Output is correct
82 Correct 3 ms 6992 KB Output is correct
83 Correct 3 ms 6992 KB Output is correct
84 Correct 4 ms 6772 KB Output is correct
85 Correct 3 ms 6736 KB Output is correct
86 Correct 3 ms 6904 KB Output is correct
87 Correct 2 ms 6736 KB Output is correct
88 Correct 85 ms 20172 KB Output is correct
89 Correct 91 ms 20172 KB Output is correct
90 Correct 81 ms 20296 KB Output is correct
91 Correct 40 ms 15944 KB Output is correct
92 Correct 47 ms 15784 KB Output is correct
93 Correct 37 ms 14560 KB Output is correct
94 Correct 36 ms 14664 KB Output is correct
95 Correct 140 ms 20272 KB Output is correct
96 Correct 118 ms 20424 KB Output is correct
97 Correct 113 ms 18760 KB Output is correct
98 Correct 121 ms 18760 KB Output is correct
99 Correct 66 ms 18772 KB Output is correct
100 Correct 66 ms 18760 KB Output is correct
101 Correct 38 ms 16112 KB Output is correct
102 Correct 40 ms 15724 KB Output is correct
103 Correct 36 ms 14676 KB Output is correct
104 Correct 37 ms 14668 KB Output is correct
105 Correct 145 ms 20256 KB Output is correct
106 Correct 135 ms 20416 KB Output is correct
107 Correct 147 ms 25664 KB Output is correct
108 Correct 160 ms 25908 KB Output is correct
109 Correct 78 ms 18096 KB Output is correct
110 Correct 70 ms 18096 KB Output is correct
111 Correct 87 ms 16576 KB Output is correct
112 Correct 84 ms 16576 KB Output is correct