# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410716 | 2021-05-23T12:32:23 Z | antontsiorvas | Cities (BOI16_cities) | C++14 | 2655 ms | 42224 KB |
#include <cstdio> #include <vector> #include <utility> #include <queue> #include <algorithm> #define lli long long int using namespace std; int N, K, M, import[7], from, to; lli weight, dp[33][100005]; vector< pair<int, lli> > data[100005]; priority_queue< pair<lli, int> > pq; lli inf = 9000000000000000000; int main(){ scanf("%d%d%d",&N,&K,&M); for(int i=1; i<=K; i++) scanf("%d",&import[i]); for(int i=1; i<=M; i++){ scanf("%d%d%lld",&from,&to,&weight); data[from].push_back(make_pair(to,weight)); data[to].push_back(make_pair(from,weight)); } int to = (1 << K); for(int i=0; i<to; i++){ for(int j=1; j<=N; j++) dp[i][j] = inf; } for(int i=0; i<K; i++) dp[1 << i][import[i+1]] = 0; for(int i=1; i<to; i++){ for(int prev=0; prev<i; prev++){ int b_or = (prev | i), b_xor = (prev ^ i); if(b_or != i || prev < b_xor) continue; for(int j=1; j<=N; j++){ dp[i][j] = min(dp[i][j],dp[prev][j]+dp[b_xor][j]); } } for(int j=1; j<=N; j++){ if(dp[i][j] != inf) pq.push(make_pair(-dp[i][j],j)); } while(!pq.empty()){ int city = pq.top().second; lli dpnum = -pq.top().first; pq.pop(); int len = data[city].size(); for(int j=0; j<len; j++){ int next_city = data[city][j].first; lli cost = data[city][j].second; if(dpnum + cost < dp[i][next_city]){ dp[i][next_city] = dpnum + cost; pq.push(make_pair(-dp[i][next_city],next_city)); } } } } lli ans = inf; for(int i=1; i<=N; i++) ans = min(ans, dp[to-1][i]); printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2636 KB | Output is correct |
2 | Correct | 2 ms | 2636 KB | Output is correct |
3 | Correct | 2 ms | 2636 KB | Output is correct |
4 | Correct | 2 ms | 2636 KB | Output is correct |
5 | Correct | 2 ms | 2764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 656 ms | 23388 KB | Output is correct |
2 | Correct | 653 ms | 22576 KB | Output is correct |
3 | Correct | 340 ms | 16208 KB | Output is correct |
4 | Correct | 97 ms | 11716 KB | Output is correct |
5 | Correct | 329 ms | 20312 KB | Output is correct |
6 | Correct | 85 ms | 11680 KB | Output is correct |
7 | Correct | 5 ms | 2892 KB | Output is correct |
8 | Correct | 4 ms | 2764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2892 KB | Output is correct |
2 | Correct | 8 ms | 3004 KB | Output is correct |
3 | Correct | 5 ms | 2892 KB | Output is correct |
4 | Correct | 5 ms | 2892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1323 ms | 29704 KB | Output is correct |
2 | Correct | 1223 ms | 28700 KB | Output is correct |
3 | Correct | 734 ms | 22444 KB | Output is correct |
4 | Correct | 755 ms | 21692 KB | Output is correct |
5 | Correct | 215 ms | 13524 KB | Output is correct |
6 | Correct | 114 ms | 14244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2645 ms | 42192 KB | Output is correct |
2 | Correct | 2655 ms | 42224 KB | Output is correct |
3 | Correct | 2549 ms | 41376 KB | Output is correct |
4 | Correct | 1593 ms | 35000 KB | Output is correct |
5 | Correct | 1434 ms | 27896 KB | Output is correct |
6 | Correct | 336 ms | 15012 KB | Output is correct |
7 | Correct | 145 ms | 14100 KB | Output is correct |