답안 #739550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739550 2023-05-10T15:46:51 Z Farhan_HY Autobus (COCI22_autobus) C++14
55 / 70
505 ms 11284 KB
#include <bits/stdc++.h>
#define int long long
#define F first 
#define S second 
#define T int tc; cin >> tc; while(tc--) 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
using namespace std;
const int inf = 1e18;
const int N = 1e6 + 5;
const int M = 505; 
const int LOG = 32;
const int CHAR = 26;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const float pi = atan(1) * 4;
const int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy[] = {0, -1, 1, -1, 1, 0, -1, 1};
const char d[] = {'E', 'N', 'S', 'W'};
int n, m, k, q;
vector<pair<int, int>> adj[100];
priority_queue<pair<pair<int, int>, int>> pq;
int g[100][100], dist[100][100][100], ans[100][100];

void dij(int node) {
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= n; j++)
            dist[node][i][j] = inf;
    dist[node][node][0] = 0;
    pq.push({{0, 0}, node});
    while(!pq.empty()) {
        int u = pq.top().S;
        int w = -pq.top().F.F;
        int y = -pq.top().F.S;
        pq.pop();
        for(auto x: adj[u]) {
            if (dist[node][x.F][y + 1] > dist[node][u][y] + x.S) {
                dist[node][x.F][y + 1] = dist[node][u][y] + x.S;
                pq.push({{-dist[node][x.F][y + 1], -y - 1}, x.F});
            }
        }
    }
}

main() {
    IOS
    cin >> n >> m;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) g[i][j] = inf;
    for(int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u][v] = min(g[u][v], w);
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            if (g[i][j] != inf) adj[i].push_back({j, g[i][j]});
    cin >> k >> q;
    for(int i = 1; i <= n; i++) {
        dij(i);
        for(int j = 1; j <= n; j++) {
            ans[i][j] = inf;
            for(int y = 0; y <= k; y++)
                ans[i][j] = min(ans[i][j], dist[i][j][y]);
            if (ans[i][j] == inf) ans[i][j] = -1;
        }
    }
    while(q--) {
        int u, v;
        cin >> u >> v;
        cout << ans[u][v] << '\n';
    }
}

Compilation message

Main.cpp: In function 'void dij(long long int)':
Main.cpp:32:13: warning: unused variable 'w' [-Wunused-variable]
   32 |         int w = -pq.top().F.F;
      |             ^
Main.cpp: At global scope:
Main.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 4708 KB Output is correct
2 Correct 89 ms 4644 KB Output is correct
3 Correct 90 ms 4688 KB Output is correct
4 Correct 182 ms 4668 KB Output is correct
5 Correct 178 ms 4684 KB Output is correct
6 Correct 280 ms 5008 KB Output is correct
7 Correct 304 ms 4936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 89 ms 4732 KB Output is correct
8 Correct 90 ms 4768 KB Output is correct
9 Correct 148 ms 4628 KB Output is correct
10 Correct 160 ms 4672 KB Output is correct
11 Correct 273 ms 4948 KB Output is correct
12 Correct 266 ms 5044 KB Output is correct
13 Correct 469 ms 11140 KB Output is correct
14 Correct 462 ms 11180 KB Output is correct
15 Correct 440 ms 11192 KB Output is correct
16 Correct 499 ms 11208 KB Output is correct
17 Correct 364 ms 10956 KB Output is correct
18 Correct 361 ms 11120 KB Output is correct
19 Correct 357 ms 11040 KB Output is correct
20 Correct 354 ms 11088 KB Output is correct
21 Correct 439 ms 10928 KB Output is correct
22 Correct 388 ms 10976 KB Output is correct
23 Correct 413 ms 10960 KB Output is correct
24 Correct 410 ms 11096 KB Output is correct
25 Correct 418 ms 11108 KB Output is correct
26 Correct 433 ms 11068 KB Output is correct
27 Correct 433 ms 11184 KB Output is correct
28 Correct 419 ms 11164 KB Output is correct
29 Correct 468 ms 11188 KB Output is correct
30 Correct 475 ms 11232 KB Output is correct
31 Correct 456 ms 11272 KB Output is correct
32 Correct 505 ms 11284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 90 ms 4708 KB Output is correct
8 Correct 89 ms 4644 KB Output is correct
9 Correct 90 ms 4688 KB Output is correct
10 Correct 182 ms 4668 KB Output is correct
11 Correct 178 ms 4684 KB Output is correct
12 Correct 280 ms 5008 KB Output is correct
13 Correct 304 ms 4936 KB Output is correct
14 Correct 89 ms 4732 KB Output is correct
15 Correct 90 ms 4768 KB Output is correct
16 Correct 148 ms 4628 KB Output is correct
17 Correct 160 ms 4672 KB Output is correct
18 Correct 273 ms 4948 KB Output is correct
19 Correct 266 ms 5044 KB Output is correct
20 Correct 469 ms 11140 KB Output is correct
21 Correct 462 ms 11180 KB Output is correct
22 Correct 440 ms 11192 KB Output is correct
23 Correct 499 ms 11208 KB Output is correct
24 Correct 364 ms 10956 KB Output is correct
25 Correct 361 ms 11120 KB Output is correct
26 Correct 357 ms 11040 KB Output is correct
27 Correct 354 ms 11088 KB Output is correct
28 Correct 439 ms 10928 KB Output is correct
29 Correct 388 ms 10976 KB Output is correct
30 Correct 413 ms 10960 KB Output is correct
31 Correct 410 ms 11096 KB Output is correct
32 Correct 418 ms 11108 KB Output is correct
33 Correct 433 ms 11068 KB Output is correct
34 Correct 433 ms 11184 KB Output is correct
35 Correct 419 ms 11164 KB Output is correct
36 Correct 468 ms 11188 KB Output is correct
37 Correct 475 ms 11232 KB Output is correct
38 Correct 456 ms 11272 KB Output is correct
39 Correct 505 ms 11284 KB Output is correct
40 Correct 79 ms 4608 KB Output is correct
41 Runtime error 5 ms 972 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -