답안 #1035734

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

using namespace std;

const int maxn = 2000005;
const long long inf = (1LL << 61);

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)
    {
        if (d[i].second == inf) continue;

        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 21 ms 47196 KB Output is correct
2 Correct 21 ms 47324 KB Output is correct
3 Correct 20 ms 47388 KB Output is correct
4 Correct 22 ms 47432 KB Output is correct
5 Correct 21 ms 47704 KB Output is correct
6 Correct 21 ms 47708 KB Output is correct
7 Correct 76 ms 62344 KB Output is correct
8 Correct 86 ms 62412 KB Output is correct
9 Correct 83 ms 63008 KB Output is correct
10 Correct 25 ms 47192 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 20 ms 47432 KB Output is correct
13 Correct 24 ms 47452 KB Output is correct
14 Correct 57 ms 59216 KB Output is correct
15 Correct 141 ms 63640 KB Output is correct
16 Correct 20 ms 47452 KB Output is correct
17 Correct 21 ms 47448 KB Output is correct
18 Correct 83 ms 62804 KB Output is correct
19 Correct 19 ms 47196 KB Output is correct
20 Correct 19 ms 47392 KB Output is correct
21 Correct 23 ms 47452 KB Output is correct
22 Correct 21 ms 47448 KB Output is correct
23 Correct 56 ms 59372 KB Output is correct
24 Correct 154 ms 63624 KB Output is correct
25 Correct 21 ms 47192 KB Output is correct
26 Correct 23 ms 47708 KB Output is correct
27 Correct 95 ms 68544 KB Output is correct
28 Correct 74 ms 59544 KB Output is correct
29 Correct 71 ms 59476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47192 KB Output is correct
2 Correct 20 ms 47196 KB Output is correct
3 Correct 21 ms 47432 KB Output is correct
4 Correct 22 ms 47344 KB Output is correct
5 Correct 21 ms 47448 KB Output is correct
6 Correct 20 ms 47452 KB Output is correct
7 Correct 20 ms 47452 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 19 ms 47244 KB Output is correct
10 Correct 20 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 20 ms 47448 KB Output is correct
13 Correct 20 ms 47448 KB Output is correct
14 Correct 21 ms 47232 KB Output is correct
15 Correct 21 ms 47372 KB Output is correct
16 Correct 23 ms 47452 KB Output is correct
17 Correct 22 ms 47196 KB Output is correct
18 Correct 20 ms 47196 KB Output is correct
19 Correct 20 ms 47196 KB Output is correct
20 Correct 20 ms 47452 KB Output is correct
21 Correct 20 ms 47448 KB Output is correct
22 Correct 20 ms 47448 KB Output is correct
23 Correct 20 ms 47448 KB Output is correct
24 Correct 21 ms 47452 KB Output is correct
25 Correct 20 ms 47452 KB Output is correct
26 Correct 20 ms 47448 KB Output is correct
27 Correct 22 ms 47320 KB Output is correct
28 Correct 19 ms 47196 KB Output is correct
29 Correct 20 ms 47196 KB Output is correct
30 Correct 20 ms 47196 KB Output is correct
31 Correct 20 ms 47324 KB Output is correct
32 Correct 21 ms 47208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47192 KB Output is correct
2 Correct 20 ms 47196 KB Output is correct
3 Correct 21 ms 47432 KB Output is correct
4 Correct 22 ms 47344 KB Output is correct
5 Correct 21 ms 47448 KB Output is correct
6 Correct 20 ms 47452 KB Output is correct
7 Correct 20 ms 47452 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 19 ms 47244 KB Output is correct
10 Correct 20 ms 47452 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 20 ms 47448 KB Output is correct
13 Correct 20 ms 47448 KB Output is correct
14 Correct 21 ms 47232 KB Output is correct
15 Correct 21 ms 47372 KB Output is correct
16 Correct 23 ms 47452 KB Output is correct
17 Correct 22 ms 47196 KB Output is correct
18 Correct 20 ms 47196 KB Output is correct
19 Correct 20 ms 47196 KB Output is correct
20 Correct 20 ms 47452 KB Output is correct
21 Correct 20 ms 47448 KB Output is correct
22 Correct 20 ms 47448 KB Output is correct
23 Correct 20 ms 47448 KB Output is correct
24 Correct 21 ms 47452 KB Output is correct
25 Correct 20 ms 47452 KB Output is correct
26 Correct 20 ms 47448 KB Output is correct
27 Correct 22 ms 47320 KB Output is correct
28 Correct 19 ms 47196 KB Output is correct
29 Correct 20 ms 47196 KB Output is correct
30 Correct 20 ms 47196 KB Output is correct
31 Correct 20 ms 47324 KB Output is correct
32 Correct 21 ms 47208 KB Output is correct
33 Correct 21 ms 47708 KB Output is correct
34 Correct 22 ms 47708 KB Output is correct
35 Correct 21 ms 47452 KB Output is correct
36 Correct 22 ms 47444 KB Output is correct
37 Correct 22 ms 47452 KB Output is correct
38 Correct 27 ms 47452 KB Output is correct
39 Correct 23 ms 47440 KB Output is correct
40 Correct 21 ms 47708 KB Output is correct
41 Correct 21 ms 47440 KB Output is correct
42 Correct 22 ms 47452 KB Output is correct
43 Correct 21 ms 47704 KB Output is correct
44 Correct 22 ms 47708 KB Output is correct
45 Correct 21 ms 47452 KB Output is correct
46 Correct 21 ms 47500 KB Output is correct
47 Correct 22 ms 47704 KB Output is correct
48 Correct 22 ms 47452 KB Output is correct
49 Correct 20 ms 47592 KB Output is correct
50 Correct 21 ms 47448 KB Output is correct
51 Correct 21 ms 47712 KB Output is correct
52 Correct 21 ms 47644 KB Output is correct
53 Correct 22 ms 47704 KB Output is correct
54 Correct 21 ms 47744 KB Output is correct
55 Correct 23 ms 47512 KB Output is correct
56 Correct 23 ms 47452 KB Output is correct
57 Correct 22 ms 47452 KB Output is correct
58 Correct 23 ms 47576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47196 KB Output is correct
2 Correct 21 ms 47324 KB Output is correct
3 Correct 20 ms 47388 KB Output is correct
4 Correct 22 ms 47432 KB Output is correct
5 Correct 21 ms 47704 KB Output is correct
6 Correct 21 ms 47708 KB Output is correct
7 Correct 76 ms 62344 KB Output is correct
8 Correct 86 ms 62412 KB Output is correct
9 Correct 83 ms 63008 KB Output is correct
10 Correct 25 ms 47192 KB Output is correct
11 Correct 20 ms 47452 KB Output is correct
12 Correct 20 ms 47432 KB Output is correct
13 Correct 24 ms 47452 KB Output is correct
14 Correct 57 ms 59216 KB Output is correct
15 Correct 141 ms 63640 KB Output is correct
16 Correct 20 ms 47452 KB Output is correct
17 Correct 21 ms 47448 KB Output is correct
18 Correct 83 ms 62804 KB Output is correct
19 Correct 19 ms 47196 KB Output is correct
20 Correct 19 ms 47392 KB Output is correct
21 Correct 23 ms 47452 KB Output is correct
22 Correct 21 ms 47448 KB Output is correct
23 Correct 56 ms 59372 KB Output is correct
24 Correct 154 ms 63624 KB Output is correct
25 Correct 21 ms 47192 KB Output is correct
26 Correct 23 ms 47708 KB Output is correct
27 Correct 95 ms 68544 KB Output is correct
28 Correct 74 ms 59544 KB Output is correct
29 Correct 71 ms 59476 KB Output is correct
30 Correct 20 ms 47192 KB Output is correct
31 Correct 20 ms 47196 KB Output is correct
32 Correct 21 ms 47432 KB Output is correct
33 Correct 22 ms 47344 KB Output is correct
34 Correct 21 ms 47448 KB Output is correct
35 Correct 20 ms 47452 KB Output is correct
36 Correct 20 ms 47452 KB Output is correct
37 Correct 20 ms 47452 KB Output is correct
38 Correct 19 ms 47244 KB Output is correct
39 Correct 20 ms 47452 KB Output is correct
40 Correct 20 ms 47452 KB Output is correct
41 Correct 20 ms 47448 KB Output is correct
42 Correct 20 ms 47448 KB Output is correct
43 Correct 21 ms 47232 KB Output is correct
44 Correct 21 ms 47372 KB Output is correct
45 Correct 23 ms 47452 KB Output is correct
46 Correct 22 ms 47196 KB Output is correct
47 Correct 20 ms 47196 KB Output is correct
48 Correct 20 ms 47196 KB Output is correct
49 Correct 20 ms 47452 KB Output is correct
50 Correct 20 ms 47448 KB Output is correct
51 Correct 20 ms 47448 KB Output is correct
52 Correct 20 ms 47448 KB Output is correct
53 Correct 21 ms 47452 KB Output is correct
54 Correct 20 ms 47452 KB Output is correct
55 Correct 20 ms 47448 KB Output is correct
56 Correct 22 ms 47320 KB Output is correct
57 Correct 19 ms 47196 KB Output is correct
58 Correct 20 ms 47196 KB Output is correct
59 Correct 20 ms 47196 KB Output is correct
60 Correct 20 ms 47324 KB Output is correct
61 Correct 21 ms 47208 KB Output is correct
62 Correct 21 ms 47708 KB Output is correct
63 Correct 22 ms 47708 KB Output is correct
64 Correct 21 ms 47452 KB Output is correct
65 Correct 22 ms 47444 KB Output is correct
66 Correct 22 ms 47452 KB Output is correct
67 Correct 27 ms 47452 KB Output is correct
68 Correct 23 ms 47440 KB Output is correct
69 Correct 21 ms 47708 KB Output is correct
70 Correct 21 ms 47440 KB Output is correct
71 Correct 22 ms 47452 KB Output is correct
72 Correct 21 ms 47704 KB Output is correct
73 Correct 22 ms 47708 KB Output is correct
74 Correct 21 ms 47452 KB Output is correct
75 Correct 21 ms 47500 KB Output is correct
76 Correct 22 ms 47704 KB Output is correct
77 Correct 22 ms 47452 KB Output is correct
78 Correct 20 ms 47592 KB Output is correct
79 Correct 21 ms 47448 KB Output is correct
80 Correct 21 ms 47712 KB Output is correct
81 Correct 21 ms 47644 KB Output is correct
82 Correct 22 ms 47704 KB Output is correct
83 Correct 21 ms 47744 KB Output is correct
84 Correct 23 ms 47512 KB Output is correct
85 Correct 23 ms 47452 KB Output is correct
86 Correct 22 ms 47452 KB Output is correct
87 Correct 23 ms 47576 KB Output is correct
88 Correct 110 ms 62520 KB Output is correct
89 Correct 110 ms 62588 KB Output is correct
90 Correct 112 ms 65328 KB Output is correct
91 Correct 61 ms 56400 KB Output is correct
92 Correct 61 ms 56404 KB Output is correct
93 Correct 61 ms 59984 KB Output is correct
94 Correct 60 ms 59960 KB Output is correct
95 Correct 160 ms 65064 KB Output is correct
96 Correct 150 ms 63684 KB Output is correct
97 Correct 147 ms 64208 KB Output is correct
98 Correct 131 ms 64340 KB Output is correct
99 Correct 83 ms 64336 KB Output is correct
100 Correct 80 ms 64340 KB Output is correct
101 Correct 62 ms 56400 KB Output is correct
102 Correct 60 ms 56404 KB Output is correct
103 Correct 62 ms 59984 KB Output is correct
104 Correct 62 ms 60128 KB Output is correct
105 Correct 172 ms 65060 KB Output is correct
106 Correct 164 ms 65072 KB Output is correct
107 Correct 138 ms 69896 KB Output is correct
108 Correct 160 ms 70068 KB Output is correct
109 Execution timed out 2066 ms 58556 KB Time limit exceeded
110 Halted 0 ms 0 KB -