답안 #991210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991210 2024-06-01T15:09:20 Z model_code Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
307 ms 23764 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

using P = pair<long long, int>;

struct edge{
    int to;
    long long cost;
};

constexpr long long inf = 1e18;

int main(){
    int n, m;
    cin >> n >> m;
    
    int s, t;
    long long l, k;
    cin >> s >> t >> l >> k;
    s--;
    t--;

    vector<vector<edge>> g(n);
    for(int i = 0; i < m; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;

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

    priority_queue<P, vector<P>, greater<P>> que;
    vector<long long> dist_from_s(n, inf), dist_from_t(n, inf);

    dist_from_s[s] = 0;
    que.push({0, s});
    while(!que.empty()){
        auto [dist, now] = que.top();
        que.pop();

        if(dist_from_s[now] < dist){
            continue;
        }

        for(auto [nxt, c]: g[now]){
            if(dist_from_s[nxt] > dist + c){
                dist_from_s[nxt] = dist + c;
                que.push({dist + c, nxt});
            }
        }
    }

    dist_from_t[t] = 0;
    que.push({0, t});
    while(!que.empty()){
        auto [dist, now] = que.top();
        que.pop();

        if(dist_from_t[now] < dist){
            continue;
        }

        for(auto [nxt, c]: g[now]){
            if(dist_from_t[nxt] > dist + c){
                dist_from_t[nxt] = dist + c;
                que.push({dist + c, nxt});
            }
        }
    }

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

    long long ans = 0;
    sort(dist_from_t.begin(), dist_from_t.end());

    for(int u = 0; u < n; u++){
        long long ok = k - l - dist_from_s[u];
        ans += lower_bound(dist_from_t.begin(), dist_from_t.end(), ok + 1) - dist_from_t.begin();
    }

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 94 ms 18776 KB Output is correct
8 Correct 115 ms 18740 KB Output is correct
9 Correct 103 ms 18740 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 61 ms 13400 KB Output is correct
15 Correct 190 ms 19148 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 136 ms 17536 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 62 ms 13444 KB Output is correct
24 Correct 177 ms 19236 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 128 ms 23668 KB Output is correct
28 Correct 101 ms 15052 KB Output is correct
29 Correct 105 ms 13904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 360 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 360 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 2 ms 856 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 628 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 592 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 3 ms 600 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 856 KB Output is correct
49 Correct 3 ms 604 KB Output is correct
50 Correct 1 ms 432 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 3 ms 604 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 94 ms 18776 KB Output is correct
8 Correct 115 ms 18740 KB Output is correct
9 Correct 103 ms 18740 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 61 ms 13400 KB Output is correct
15 Correct 190 ms 19148 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 136 ms 17536 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 62 ms 13444 KB Output is correct
24 Correct 177 ms 19236 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 128 ms 23668 KB Output is correct
28 Correct 101 ms 15052 KB Output is correct
29 Correct 105 ms 13904 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 432 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 360 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 2 ms 856 KB Output is correct
63 Correct 2 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 2 ms 604 KB Output is correct
66 Correct 2 ms 600 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 2 ms 604 KB Output is correct
69 Correct 2 ms 604 KB Output is correct
70 Correct 2 ms 628 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 3 ms 604 KB Output is correct
73 Correct 3 ms 592 KB Output is correct
74 Correct 3 ms 588 KB Output is correct
75 Correct 3 ms 600 KB Output is correct
76 Correct 2 ms 604 KB Output is correct
77 Correct 2 ms 856 KB Output is correct
78 Correct 3 ms 604 KB Output is correct
79 Correct 1 ms 432 KB Output is correct
80 Correct 3 ms 604 KB Output is correct
81 Correct 3 ms 604 KB Output is correct
82 Correct 3 ms 604 KB Output is correct
83 Correct 4 ms 604 KB Output is correct
84 Correct 2 ms 604 KB Output is correct
85 Correct 2 ms 604 KB Output is correct
86 Correct 3 ms 604 KB Output is correct
87 Correct 3 ms 604 KB Output is correct
88 Correct 171 ms 19024 KB Output is correct
89 Correct 179 ms 19024 KB Output is correct
90 Correct 202 ms 19028 KB Output is correct
91 Correct 105 ms 11092 KB Output is correct
92 Correct 101 ms 10708 KB Output is correct
93 Correct 84 ms 13396 KB Output is correct
94 Correct 77 ms 13396 KB Output is correct
95 Correct 278 ms 19736 KB Output is correct
96 Correct 300 ms 19760 KB Output is correct
97 Correct 263 ms 18512 KB Output is correct
98 Correct 262 ms 18700 KB Output is correct
99 Correct 144 ms 17612 KB Output is correct
100 Correct 176 ms 17492 KB Output is correct
101 Correct 134 ms 11092 KB Output is correct
102 Correct 118 ms 10624 KB Output is correct
103 Correct 88 ms 13396 KB Output is correct
104 Correct 87 ms 13388 KB Output is correct
105 Correct 307 ms 19836 KB Output is correct
106 Correct 283 ms 19724 KB Output is correct
107 Correct 218 ms 23740 KB Output is correct
108 Correct 241 ms 23764 KB Output is correct
109 Correct 177 ms 15172 KB Output is correct
110 Correct 139 ms 15012 KB Output is correct
111 Correct 145 ms 14604 KB Output is correct
112 Correct 230 ms 14516 KB Output is correct