이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define F first
#define S second
int best_path(int n, int k, int h[][2], int L[]){
vector<pair<int,int>> roads;
vector<int> w;
for (int i = 0; i < n - 1; i++){
///cout << L[i] << " " << h[i][0] << " " << h[i][1] << "\n";
if (L[i] == k) return 1;
if(L[i] > k) continue;
roads.push_back({h[i][0], h[i][1]});
w.push_back(L[i]);
}
vector<vii> graph(n);
for (int i = 0; i < roads.size(); i++){
int u = roads[i].F, v = roads[i].S;
graph[u].push_back({v,w[i]});
graph[v].push_back({u,w[i]});
}
int ans = INT_MAX;
vector<bool> temp(n,0);
vector<vector<bool>> vis(n, temp);
for (int s = 0; s < n; s++){
// Definir que punto iniciara el algoritmo
// Guaradar info como v,w
vector<int> peso(n,INT_MAX);
vector<int> dist(n, 0);
// Aqui dist[s], s es el inicio
peso[s] = 0;
vis[s][s] = 1;
priority_queue<ii,vii,greater<ii>> pq;
pq.push(ii(0,s));
while(!pq.empty()){
int d = pq.top().F;
int u = pq.top().S;
pq.pop();
if (d > peso[u]) continue;
for (auto x : graph[u]){
if(vis[x.F][u]) continue;
if(peso[u] + x.S < peso[x.F]){
peso[x.F] = peso[u] + x.S;
dist[x.F] = dist[u] + 1;
// Se invierte de v,w a w,v
pq.push(ii(peso[x.F],x.F));
vis[u][x.F] = 1;
}
}
}
auto f = find(peso.begin(), peso.end(), k);
if (f != peso.end()){
int p = f - peso.begin();
ans = min(ans, dist[p]);
}
//cout << s << " : ";
//for (int i = 0; i < n; i++) cout << peso[i] << "," << dist[i] << " ";
cout << "\n";
}
if (ans == INT_MAX) return -1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < roads.size(); i++){
| ~~^~~~~~~~~~~~~~
# | 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... |