제출 #533332

#제출 시각아이디문제언어결과실행 시간메모리
533332ddy888Autobus (COCI22_autobus)C++17
0 / 70
2 ms332 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int INF = 1e9 + 7; int N, M, K, Q, dist[80][80], path[80][80]; signed main() { fast; cin >> N >> M; for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) dist[i][j] = INF, path[i][j] = INF; for (int i = 1; i <= M; ++i) { int u, v, c; cin >> u >> v >> c; dist[u][v] = c; path[u][v] = 1; } cin >> K >> Q; for (int k = 1; k <= N; ++k) { for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { if (i == j) dist[i][j] = 0, path[i][j] = 0; int new_dist = dist[i][k] + dist[k][j]; int new_path = path[i][k] + path[k][j]; if (new_dist < dist[i][j] && new_path <= K) { dist[i][j] = new_dist; path[i][j] = new_path; } else if (new_dist == dist[i][j] && new_path < path[i][j]) { path[i][j] = new_path; } } } } while (Q--) { int u, v; cin >> u >> v; if (dist[u][v] == INF) cout << -1 << '\n'; else cout << dist[u][v] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...