# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56758 | 2018-07-12T12:20:11 Z | wjoao | Cities (BOI16_cities) | C++11 | 381 ms | 29236 KB |
#include<bits/stdc++.h> #define maxn 100010 #define inf 0x3f3f3f3f3f3f3f3f using namespace std; long long n, m, k, a, b, c, dist[maxn], ini; bool is_important[maxn]; vector< pair<long long, long long> > g[maxn]; int main(){ scanf(" %lld %lld %lld", &n, &k, &m); for(long long i = 0; i < k; i++){ scanf(" %lld", &a); if( i == 0 ) ini = a; is_important[a] = true; } for(long long i = 0; i < m; i++){ scanf(" %lld %lld %lld", &a, &b, &c); g[a].push_back({b,c}); g[b].push_back({a,c}); } memset(dist, inf, sizeof dist); priority_queue< pair<long long, long long>, vector< pair<long long, long long> >, greater< pair<long long, long long> > > fp; long long res = 0; dist[ini] = 0; fp.push({0, ini}); while(!fp.empty()){ long long d = fp.top().first; long long v = fp.top().second; fp.pop(); if(dist[v] < d ) continue; if(is_important[v]) { res += dist[v]; dist[v] = 0; } for(long long i = 0; i < g[v].size(); i++){ long long u = g[v][i].first; long long d2 = g[v][i].second; if( dist[v] + d2 < dist[u] ){ dist[u] = dist[v] + d2; fp.push({dist[u], u}); } } } printf("%lld\n", res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 3448 KB | Output is correct |
2 | Correct | 6 ms | 3560 KB | Output is correct |
3 | Incorrect | 6 ms | 3672 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 335 ms | 20592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 20592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 328 ms | 24876 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 381 ms | 29236 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |