이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int best_path(int n, int k, int H[][2], int L[]) {
vector<int> adj[n];
ll dis[n][n] {};
int cost[n][n], D[n][n] {};
for(int i = 0; i < n - 1; i++) {
adj[H[i][0]].push_back(H[i][1]);
adj[H[i][1]].push_back(H[i][0]);
cost[H[i][0]][H[i][1]] = L[i];
cost[H[i][1]][H[i][0]] = L[i];
}
for(int i = 0; i < n; i++) {
queue<int> q;
q.push(i);
while(!q.empty()) {
int x = q.front();
q.pop();
for(int X : adj[x]) {
dis[i][X] = dis[i][x] + cost[x][X];
D[i][X] = D[i][x] + 1;
q.push(X);
}
}
}
int mn = 1e9;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i == j) continue;
if(dis[i][j] == k) {
mn = min(mn, D[i][j]);
}
}
}
if(mn == 1e9) mn = -1;
return mn;
}
//int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout << best_path(3, 3, {{0, 1}, {1, 2}}, {1, 1}) << '\n';
// return 0;
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |