답안 #1037432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037432 2024-07-28T20:45:56 Z aaaaaarroz Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
231 ms 28624 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 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 95 ms 21140 KB Output is correct
8 Correct 109 ms 21248 KB Output is correct
9 Correct 104 ms 21056 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 63 ms 14932 KB Output is correct
15 Correct 174 ms 22072 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 113 ms 20540 KB Output is correct
19 Correct 0 ms 348 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 14976 KB Output is correct
24 Correct 176 ms 22220 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 131 ms 28624 KB Output is correct
28 Correct 105 ms 17456 KB Output is correct
29 Correct 104 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 356 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 348 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 356 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 348 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 428 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 2 ms 612 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 600 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 856 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 3 ms 616 KB Output is correct
52 Correct 2 ms 604 KB Output is correct
53 Correct 3 ms 860 KB Output is correct
54 Correct 3 ms 860 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 95 ms 21140 KB Output is correct
8 Correct 109 ms 21248 KB Output is correct
9 Correct 104 ms 21056 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 63 ms 14932 KB Output is correct
15 Correct 174 ms 22072 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 113 ms 20540 KB Output is correct
19 Correct 0 ms 348 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 14976 KB Output is correct
24 Correct 176 ms 22220 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 131 ms 28624 KB Output is correct
28 Correct 105 ms 17456 KB Output is correct
29 Correct 104 ms 16724 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 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 348 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 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 432 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 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 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 428 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 2 ms 604 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 2 ms 604 KB Output is correct
66 Correct 2 ms 604 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 2 ms 612 KB Output is correct
69 Correct 2 ms 600 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 3 ms 604 KB Output is correct
73 Correct 2 ms 604 KB Output is correct
74 Correct 3 ms 604 KB Output is correct
75 Correct 3 ms 604 KB Output is correct
76 Correct 2 ms 600 KB Output is correct
77 Correct 2 ms 604 KB Output is correct
78 Correct 2 ms 856 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 3 ms 616 KB Output is correct
81 Correct 2 ms 604 KB Output is correct
82 Correct 3 ms 860 KB Output is correct
83 Correct 3 ms 860 KB Output is correct
84 Correct 2 ms 604 KB Output is correct
85 Correct 2 ms 604 KB Output is correct
86 Correct 2 ms 604 KB Output is correct
87 Correct 2 ms 600 KB Output is correct
88 Correct 172 ms 23676 KB Output is correct
89 Correct 167 ms 23680 KB Output is correct
90 Correct 154 ms 23632 KB Output is correct
91 Correct 99 ms 14420 KB Output is correct
92 Correct 98 ms 14148 KB Output is correct
93 Correct 75 ms 15700 KB Output is correct
94 Correct 75 ms 15724 KB Output is correct
95 Correct 206 ms 24088 KB Output is correct
96 Correct 183 ms 24444 KB Output is correct
97 Correct 187 ms 23124 KB Output is correct
98 Correct 199 ms 23132 KB Output is correct
99 Correct 123 ms 22072 KB Output is correct
100 Correct 124 ms 22100 KB Output is correct
101 Correct 86 ms 14460 KB Output is correct
102 Correct 99 ms 14160 KB Output is correct
103 Correct 76 ms 15604 KB Output is correct
104 Correct 73 ms 15752 KB Output is correct
105 Correct 190 ms 24264 KB Output is correct
106 Correct 231 ms 24192 KB Output is correct
107 Correct 185 ms 28600 KB Output is correct
108 Correct 184 ms 28344 KB Output is correct
109 Correct 133 ms 18620 KB Output is correct
110 Correct 130 ms 18740 KB Output is correct
111 Correct 132 ms 17508 KB Output is correct
112 Correct 137 ms 17612 KB Output is correct