답안 #525981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525981 2022-02-13T11:58:45 Z model_code Autobus (COCI22_autobus) C++17
70 / 70
133 ms 452 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 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 3 ms 284 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 11 ms 380 KB Output is correct
8 Correct 28 ms 352 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 16 ms 332 KB Output is correct
11 Correct 6 ms 332 KB Output is correct
12 Correct 20 ms 380 KB Output is correct
13 Correct 94 ms 324 KB Output is correct
14 Correct 115 ms 332 KB Output is correct
15 Correct 117 ms 332 KB Output is correct
16 Correct 90 ms 308 KB Output is correct
17 Correct 93 ms 312 KB Output is correct
18 Correct 88 ms 324 KB Output is correct
19 Correct 116 ms 324 KB Output is correct
20 Correct 99 ms 308 KB Output is correct
21 Correct 99 ms 312 KB Output is correct
22 Correct 97 ms 312 KB Output is correct
23 Correct 95 ms 332 KB Output is correct
24 Correct 98 ms 324 KB Output is correct
25 Correct 88 ms 324 KB Output is correct
26 Correct 99 ms 312 KB Output is correct
27 Correct 98 ms 308 KB Output is correct
28 Correct 94 ms 324 KB Output is correct
29 Correct 85 ms 308 KB Output is correct
30 Correct 92 ms 312 KB Output is correct
31 Correct 133 ms 320 KB Output is correct
32 Correct 114 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 3 ms 284 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 11 ms 380 KB Output is correct
15 Correct 28 ms 352 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 16 ms 332 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 20 ms 380 KB Output is correct
20 Correct 94 ms 324 KB Output is correct
21 Correct 115 ms 332 KB Output is correct
22 Correct 117 ms 332 KB Output is correct
23 Correct 90 ms 308 KB Output is correct
24 Correct 93 ms 312 KB Output is correct
25 Correct 88 ms 324 KB Output is correct
26 Correct 116 ms 324 KB Output is correct
27 Correct 99 ms 308 KB Output is correct
28 Correct 99 ms 312 KB Output is correct
29 Correct 97 ms 312 KB Output is correct
30 Correct 95 ms 332 KB Output is correct
31 Correct 98 ms 324 KB Output is correct
32 Correct 88 ms 324 KB Output is correct
33 Correct 99 ms 312 KB Output is correct
34 Correct 98 ms 308 KB Output is correct
35 Correct 94 ms 324 KB Output is correct
36 Correct 85 ms 308 KB Output is correct
37 Correct 92 ms 312 KB Output is correct
38 Correct 133 ms 320 KB Output is correct
39 Correct 114 ms 356 KB Output is correct
40 Correct 8 ms 376 KB Output is correct
41 Correct 32 ms 452 KB Output is correct
42 Correct 5 ms 332 KB Output is correct
43 Correct 47 ms 372 KB Output is correct
44 Correct 6 ms 332 KB Output is correct
45 Correct 40 ms 332 KB Output is correct
46 Correct 84 ms 312 KB Output is correct
47 Correct 102 ms 324 KB Output is correct
48 Correct 128 ms 312 KB Output is correct
49 Correct 109 ms 312 KB Output is correct
50 Correct 95 ms 308 KB Output is correct
51 Correct 94 ms 352 KB Output is correct
52 Correct 86 ms 332 KB Output is correct
53 Correct 116 ms 352 KB Output is correct
54 Correct 90 ms 316 KB Output is correct
55 Correct 109 ms 312 KB Output is correct
56 Correct 110 ms 352 KB Output is correct
57 Correct 112 ms 308 KB Output is correct
58 Correct 88 ms 324 KB Output is correct
59 Correct 98 ms 332 KB Output is correct
60 Correct 117 ms 312 KB Output is correct
61 Correct 116 ms 320 KB Output is correct
62 Correct 86 ms 312 KB Output is correct
63 Correct 91 ms 312 KB Output is correct
64 Correct 101 ms 312 KB Output is correct
65 Correct 109 ms 320 KB Output is correct