제출 #719224

#제출 시각아이디문제언어결과실행 시간메모리
719224ChrisM2309경주 (Race) (IOI11_race)C++17
9 / 100
3053 ms9604 KiB
#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; 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; 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(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)); } } } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...