답안 #1035731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035731 2024-07-26T14:14:37 Z borisAngelov Construction Project 2 (JOI24_ho_t2) C++17
53 / 100
2000 ms 27796 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;
const long long inf = 1e18;

int n, m, s, t;
long long L, K;

long long ds[maxn], dt[maxn];
pair<long long, long long> d[maxn];

vector<pair<int, int>> g[maxn];

void dijkstra(int start, long long dist[])
{
    for (int i = 1; i <= n; ++i)
    {
        dist[i] = inf;
    }

    priority_queue<pair<long long, int>> pq;
    pq.push({0, start});
    dist[start] = 0;

    while (!pq.empty())
    {
        auto top = pq.top();
        pq.pop();

        int node = top.second;
        long long curr = -top.first;

        for (int i = 0; i < g[node].size(); ++i)
        {
            if (dist[g[node][i].first] > curr + g[node][i].second)
            {
                dist[g[node][i].first] = curr + g[node][i].second;
                pq.push({-dist[g[node][i].first], g[node][i].first});
            }
        }
    }
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> m >> s >> t >> L >> K;

    for (int i = 1; i <= m; ++i)
    {
        int x, y, w;
        cin >> x >> y >> w;

        g[x].push_back({y, w});
        g[y].push_back({x, w});
    }

    dijkstra(s, ds);
    dijkstra(t, dt);

    if (ds[t] <= K)
    {
        cout << ((1LL * n) * (1LL * (n - 1))) / 2 << endl;
        return 0;
    }

    for (int i = 1; i <= n; ++i)
    {
        d[i] = {ds[i], dt[i]};
    }

    sort(d + 1, d + n + 1);

    long long ans = 0;

    for (int i = 2; i <= n; ++i)
    {
        int l = 1;
        int r = i - 1;

        while (l <= r)
        {
            int mid = (l + r) / 2;

            if (d[i].second + d[mid].first <= K - L)
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }

        ans += r;
    }

    cout << ans << endl;

    return 0;
}

Compilation message

Main.cpp: In function 'void dijkstra(int, long long int*)':
Main.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 0; i < g[node].size(); ++i)
      |                         ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5256 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 55 ms 20176 KB Output is correct
8 Correct 74 ms 20136 KB Output is correct
9 Correct 61 ms 20580 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5252 KB Output is correct
13 Correct 4 ms 5212 KB Output is correct
14 Correct 40 ms 17072 KB Output is correct
15 Correct 122 ms 21416 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 5464 KB Output is correct
18 Correct 62 ms 20560 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5180 KB Output is correct
22 Correct 4 ms 5212 KB Output is correct
23 Correct 37 ms 16920 KB Output is correct
24 Correct 129 ms 21444 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 75 ms 26348 KB Output is correct
28 Correct 56 ms 17308 KB Output is correct
29 Correct 52 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 5264 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 5172 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5164 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 5152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 5264 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 5172 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5164 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 5152 KB Output is correct
33 Correct 3 ms 5468 KB Output is correct
34 Correct 3 ms 5468 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5356 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 4 ms 5212 KB Output is correct
40 Correct 3 ms 5464 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 4 ms 5212 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 3 ms 5212 KB Output is correct
51 Correct 4 ms 5248 KB Output is correct
52 Correct 4 ms 5468 KB Output is correct
53 Correct 4 ms 5468 KB Output is correct
54 Correct 3 ms 5468 KB Output is correct
55 Correct 6 ms 5212 KB Output is correct
56 Correct 5 ms 5212 KB Output is correct
57 Correct 3 ms 5212 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5256 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 55 ms 20176 KB Output is correct
8 Correct 74 ms 20136 KB Output is correct
9 Correct 61 ms 20580 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5252 KB Output is correct
13 Correct 4 ms 5212 KB Output is correct
14 Correct 40 ms 17072 KB Output is correct
15 Correct 122 ms 21416 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 5464 KB Output is correct
18 Correct 62 ms 20560 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5180 KB Output is correct
22 Correct 4 ms 5212 KB Output is correct
23 Correct 37 ms 16920 KB Output is correct
24 Correct 129 ms 21444 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 75 ms 26348 KB Output is correct
28 Correct 56 ms 17308 KB Output is correct
29 Correct 52 ms 17236 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 2 ms 5264 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 5172 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 2 ms 5164 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Correct 2 ms 5152 KB Output is correct
62 Correct 3 ms 5468 KB Output is correct
63 Correct 3 ms 5468 KB Output is correct
64 Correct 3 ms 5212 KB Output is correct
65 Correct 3 ms 5356 KB Output is correct
66 Correct 3 ms 5212 KB Output is correct
67 Correct 2 ms 5212 KB Output is correct
68 Correct 4 ms 5212 KB Output is correct
69 Correct 3 ms 5464 KB Output is correct
70 Correct 3 ms 5208 KB Output is correct
71 Correct 3 ms 5212 KB Output is correct
72 Correct 4 ms 5212 KB Output is correct
73 Correct 3 ms 5468 KB Output is correct
74 Correct 4 ms 5212 KB Output is correct
75 Correct 3 ms 5212 KB Output is correct
76 Correct 3 ms 5212 KB Output is correct
77 Correct 3 ms 5212 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 3 ms 5212 KB Output is correct
80 Correct 4 ms 5248 KB Output is correct
81 Correct 4 ms 5468 KB Output is correct
82 Correct 4 ms 5468 KB Output is correct
83 Correct 3 ms 5468 KB Output is correct
84 Correct 6 ms 5212 KB Output is correct
85 Correct 5 ms 5212 KB Output is correct
86 Correct 3 ms 5212 KB Output is correct
87 Correct 3 ms 5212 KB Output is correct
88 Correct 86 ms 20324 KB Output is correct
89 Correct 89 ms 20272 KB Output is correct
90 Correct 87 ms 22972 KB Output is correct
91 Correct 42 ms 14168 KB Output is correct
92 Correct 41 ms 14264 KB Output is correct
93 Correct 41 ms 17748 KB Output is correct
94 Correct 41 ms 17748 KB Output is correct
95 Correct 143 ms 22988 KB Output is correct
96 Correct 134 ms 21192 KB Output is correct
97 Correct 131 ms 22096 KB Output is correct
98 Correct 118 ms 22096 KB Output is correct
99 Correct 64 ms 22100 KB Output is correct
100 Correct 62 ms 22096 KB Output is correct
101 Correct 40 ms 14160 KB Output is correct
102 Correct 41 ms 14164 KB Output is correct
103 Correct 46 ms 17748 KB Output is correct
104 Correct 44 ms 17744 KB Output is correct
105 Correct 140 ms 22964 KB Output is correct
106 Correct 137 ms 22824 KB Output is correct
107 Correct 131 ms 27648 KB Output is correct
108 Correct 127 ms 27796 KB Output is correct
109 Execution timed out 2047 ms 16312 KB Time limit exceeded
110 Halted 0 ms 0 KB -