답안 #880559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880559 2023-11-29T16:17:40 Z tsumondai Autobus (COCI22_autobus) C++14
70 / 70
122 ms 7012 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define _ << " _ " <<

template<class> struct is_container : false_type {};
template<class... Ts> struct is_container<vector<Ts...>> : true_type {};
template<class... Ts> struct is_container<map<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};
template<class... Ts> struct is_container<set<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};
template<class... Ts> struct is_container<multiset<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_multiset<Ts...>> : true_type {};
template<class T, class = typename enable_if<is_container<T>::value>::type>
ostream& operator<<(ostream &o, T x) {
  int f = 1;
  o << "{";
  for (auto y : x) {
    o << (f ? "" : ", ") << y;
    f = 0;
  }
  return o << "}";
}
template<class T, class U>
ostream& operator<<(ostream &o, pair<T, U> x) {
  return o << "(" << x.first << ", " << x.second << ")";
}

#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int INF = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<vi> e(n, vi(n, INF));
    for (int i = 0; i < n; i++) e[i][i] = 0;
    while (m--) {
        int x, y, w;
        cin >> x >> y >> w;
        x--; y--;
        e[x][y] = min(e[x][y], w);
    }

    int k;
    cin >> k;
    k = min(k, n);
    auto sol = e;
    while (--k) {
        auto new_sol = sol; 
        for (int x = 0; x < n; x++)
            for (int y = 0; y < n; y++)
                for (int z = 0; z < n; z++)
                    new_sol[x][y] = min(new_sol[x][y], sol[x][z] + e[z][y]);
        sol = new_sol;
    }

    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if (sol[x][y] == INF) sol[x][y] = -1;
        cout << sol[x][y] << '\n';
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 11 ms 344 KB Output is correct
8 Correct 25 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 14 ms 560 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 17 ms 596 KB Output is correct
13 Correct 73 ms 6596 KB Output is correct
14 Correct 72 ms 6480 KB Output is correct
15 Correct 110 ms 6468 KB Output is correct
16 Correct 91 ms 6584 KB Output is correct
17 Correct 73 ms 6576 KB Output is correct
18 Correct 72 ms 6484 KB Output is correct
19 Correct 97 ms 6480 KB Output is correct
20 Correct 86 ms 6584 KB Output is correct
21 Correct 72 ms 6740 KB Output is correct
22 Correct 81 ms 6736 KB Output is correct
23 Correct 79 ms 6712 KB Output is correct
24 Correct 84 ms 6716 KB Output is correct
25 Correct 74 ms 6740 KB Output is correct
26 Correct 80 ms 6840 KB Output is correct
27 Correct 81 ms 6840 KB Output is correct
28 Correct 101 ms 6708 KB Output is correct
29 Correct 72 ms 6480 KB Output is correct
30 Correct 76 ms 6480 KB Output is correct
31 Correct 89 ms 7012 KB Output is correct
32 Correct 99 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 2 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 524 KB Output is correct
14 Correct 11 ms 344 KB Output is correct
15 Correct 25 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 14 ms 560 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 17 ms 596 KB Output is correct
20 Correct 73 ms 6596 KB Output is correct
21 Correct 72 ms 6480 KB Output is correct
22 Correct 110 ms 6468 KB Output is correct
23 Correct 91 ms 6584 KB Output is correct
24 Correct 73 ms 6576 KB Output is correct
25 Correct 72 ms 6484 KB Output is correct
26 Correct 97 ms 6480 KB Output is correct
27 Correct 86 ms 6584 KB Output is correct
28 Correct 72 ms 6740 KB Output is correct
29 Correct 81 ms 6736 KB Output is correct
30 Correct 79 ms 6712 KB Output is correct
31 Correct 84 ms 6716 KB Output is correct
32 Correct 74 ms 6740 KB Output is correct
33 Correct 80 ms 6840 KB Output is correct
34 Correct 81 ms 6840 KB Output is correct
35 Correct 101 ms 6708 KB Output is correct
36 Correct 72 ms 6480 KB Output is correct
37 Correct 76 ms 6480 KB Output is correct
38 Correct 89 ms 7012 KB Output is correct
39 Correct 99 ms 6480 KB Output is correct
40 Correct 7 ms 348 KB Output is correct
41 Correct 25 ms 536 KB Output is correct
42 Correct 4 ms 348 KB Output is correct
43 Correct 25 ms 472 KB Output is correct
44 Correct 5 ms 600 KB Output is correct
45 Correct 26 ms 596 KB Output is correct
46 Correct 75 ms 6484 KB Output is correct
47 Correct 85 ms 6580 KB Output is correct
48 Correct 77 ms 6612 KB Output is correct
49 Correct 95 ms 6456 KB Output is correct
50 Correct 87 ms 6484 KB Output is correct
51 Correct 79 ms 6480 KB Output is correct
52 Correct 72 ms 6484 KB Output is correct
53 Correct 96 ms 6480 KB Output is correct
54 Correct 72 ms 6736 KB Output is correct
55 Correct 79 ms 6740 KB Output is correct
56 Correct 94 ms 6588 KB Output is correct
57 Correct 122 ms 6736 KB Output is correct
58 Correct 73 ms 6740 KB Output is correct
59 Correct 85 ms 6724 KB Output is correct
60 Correct 93 ms 6848 KB Output is correct
61 Correct 101 ms 6608 KB Output is correct
62 Correct 75 ms 6532 KB Output is correct
63 Correct 95 ms 6596 KB Output is correct
64 Correct 89 ms 6480 KB Output is correct
65 Correct 95 ms 6480 KB Output is correct