제출 #384021

#제출 시각아이디문제언어결과실행 시간메모리
384021MODDIRace (IOI11_race)C++14
0 / 100
6 ms4972 KiB
#include "race.h" #include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define mp make_pair #define pb push_back #define MAX_N 500000 using namespace std; vector<pii> G[200000]; ll min(ll a, ll b){ if(a > b) return b; return a; } int best_path(int n, int k, int h[][2], int l[]) { for(int i = 0; i < n-1; i++){ G[h[i][0]].pb(mp(h[i][1], l[i])); G[h[i][1]].pb(mp(h[i][0], l[i])); } int best = 1e9; for(int i = 0; i <n; i++){ vector<pll> dist(n); bool vis[n]; memset(vis, false, sizeof(vis)); queue<pii> q; q.push(mp(i,0)); while(!q.empty()){ int at = q.front().first; int nodes = q.front().second; q.pop(); for(auto next : G[at]){ if(!vis[next.first]){ dist[next.first] = mp(dist[at].first + next.second, nodes+1); vis[next.first] = true; q.push(mp(next.first, nodes + 1)); } } } for(int j = 0; j < n; j++){ if(dist[j].first == k) best = min(best, dist[j].second); } } if(best == 1e9) return -1; return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...