Submission #526686

# Submission time Handle Problem Language Result Execution time Memory
526686 2022-02-16T01:36:14 Z joelau Autobus (COCI22_autobus) C++14
70 / 70
421 ms 2068 KB
#include <bits/stdc++.h>
using namespace std;

int N,M,K,Q, lst[75][75], dist[75][5000], inf = 1e9;
priority_queue< pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > > pq;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) lst[i][j] = i == j ? 0 : inf;
    for (int i = 0; i < M; ++i) {
        int u,v,w; cin >> u >> v >> w; u--, v--;
        lst[u][v] = min(lst[u][v],w);
    }
    cin >> K >> Q; K = min(K,N-1);
    for (int i = 0; i < N; ++i) for (int j = 0; j < N*N; ++j) dist[i][j] = inf;
    for (int i = 0; i < N; ++i) {
        dist[i][i] = 0;
        pq.emplace(0,i);
        while (!pq.empty()) {
            int d,u; tie(d,u) = pq.top(); pq.pop();
            if (d > dist[i][u]) continue;
            for (int v = 0; v < N; ++v) if (dist[i][u] + lst[u%N][v] < dist[i][u/N*N+N+v]) {
                dist[i][u/N*N+N+v] = dist[i][u] + lst[u%N][v];
                pq.emplace(dist[i][u/N*N+N+v],u/N*N+N+v);
            }
        }
    }
    while (Q--) {
        int u,v; cin >> u >> v; u--, v--;
        int ans = inf;
        for (int i = 0; i <= K; ++i) ans = min(ans,dist[u][i*N+v]);
        if (ans == inf) ans = -1;
        cout << ans << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 1816 KB Output is correct
2 Correct 184 ms 1800 KB Output is correct
3 Correct 188 ms 1812 KB Output is correct
4 Correct 211 ms 1860 KB Output is correct
5 Correct 195 ms 1816 KB Output is correct
6 Correct 254 ms 1936 KB Output is correct
7 Correct 267 ms 2068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 188 ms 1812 KB Output is correct
8 Correct 180 ms 1820 KB Output is correct
9 Correct 199 ms 1820 KB Output is correct
10 Correct 201 ms 1824 KB Output is correct
11 Correct 255 ms 1952 KB Output is correct
12 Correct 277 ms 1996 KB Output is correct
13 Correct 343 ms 1948 KB Output is correct
14 Correct 360 ms 1948 KB Output is correct
15 Correct 366 ms 1992 KB Output is correct
16 Correct 370 ms 1856 KB Output is correct
17 Correct 309 ms 1912 KB Output is correct
18 Correct 303 ms 1920 KB Output is correct
19 Correct 337 ms 1916 KB Output is correct
20 Correct 307 ms 1912 KB Output is correct
21 Correct 339 ms 1860 KB Output is correct
22 Correct 297 ms 1856 KB Output is correct
23 Correct 333 ms 1928 KB Output is correct
24 Correct 292 ms 1872 KB Output is correct
25 Correct 330 ms 1860 KB Output is correct
26 Correct 421 ms 2048 KB Output is correct
27 Correct 325 ms 1860 KB Output is correct
28 Correct 347 ms 1868 KB Output is correct
29 Correct 366 ms 2000 KB Output is correct
30 Correct 368 ms 1992 KB Output is correct
31 Correct 373 ms 1988 KB Output is correct
32 Correct 374 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 185 ms 1816 KB Output is correct
8 Correct 184 ms 1800 KB Output is correct
9 Correct 188 ms 1812 KB Output is correct
10 Correct 211 ms 1860 KB Output is correct
11 Correct 195 ms 1816 KB Output is correct
12 Correct 254 ms 1936 KB Output is correct
13 Correct 267 ms 2068 KB Output is correct
14 Correct 188 ms 1812 KB Output is correct
15 Correct 180 ms 1820 KB Output is correct
16 Correct 199 ms 1820 KB Output is correct
17 Correct 201 ms 1824 KB Output is correct
18 Correct 255 ms 1952 KB Output is correct
19 Correct 277 ms 1996 KB Output is correct
20 Correct 343 ms 1948 KB Output is correct
21 Correct 360 ms 1948 KB Output is correct
22 Correct 366 ms 1992 KB Output is correct
23 Correct 370 ms 1856 KB Output is correct
24 Correct 309 ms 1912 KB Output is correct
25 Correct 303 ms 1920 KB Output is correct
26 Correct 337 ms 1916 KB Output is correct
27 Correct 307 ms 1912 KB Output is correct
28 Correct 339 ms 1860 KB Output is correct
29 Correct 297 ms 1856 KB Output is correct
30 Correct 333 ms 1928 KB Output is correct
31 Correct 292 ms 1872 KB Output is correct
32 Correct 330 ms 1860 KB Output is correct
33 Correct 421 ms 2048 KB Output is correct
34 Correct 325 ms 1860 KB Output is correct
35 Correct 347 ms 1868 KB Output is correct
36 Correct 366 ms 2000 KB Output is correct
37 Correct 368 ms 1992 KB Output is correct
38 Correct 373 ms 1988 KB Output is correct
39 Correct 374 ms 1992 KB Output is correct
40 Correct 187 ms 1804 KB Output is correct
41 Correct 176 ms 1740 KB Output is correct
42 Correct 222 ms 1944 KB Output is correct
43 Correct 194 ms 1820 KB Output is correct
44 Correct 251 ms 1936 KB Output is correct
45 Correct 271 ms 1940 KB Output is correct
46 Correct 350 ms 1872 KB Output is correct
47 Correct 374 ms 1948 KB Output is correct
48 Correct 350 ms 1948 KB Output is correct
49 Correct 347 ms 1868 KB Output is correct
50 Correct 300 ms 1844 KB Output is correct
51 Correct 327 ms 1852 KB Output is correct
52 Correct 330 ms 1864 KB Output is correct
53 Correct 311 ms 1920 KB Output is correct
54 Correct 333 ms 1920 KB Output is correct
55 Correct 327 ms 1868 KB Output is correct
56 Correct 299 ms 1920 KB Output is correct
57 Correct 330 ms 1860 KB Output is correct
58 Correct 345 ms 1932 KB Output is correct
59 Correct 335 ms 1932 KB Output is correct
60 Correct 326 ms 1948 KB Output is correct
61 Correct 331 ms 1988 KB Output is correct
62 Correct 384 ms 1988 KB Output is correct
63 Correct 380 ms 1988 KB Output is correct
64 Correct 392 ms 1992 KB Output is correct
65 Correct 408 ms 1988 KB Output is correct