# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
107689 |
2019-04-25T13:12:57 Z |
Kepperoni |
Cities (BOI16_cities) |
C++14 |
|
6000 ms |
241612 KB |
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int MAXN = 1e5 + 10;
ll n, m, kk;
vector<pii> k[MAXN];
ll di[MAXN][40];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n >> kk >> m;
for(int i=0; i<=n; i++)
for(int j=0; j<40; j++)
di[i][j] = 1e16;
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> q;
for(int i=0; i<kk; i++){
int cu; cin >> cu;
di[cu][1<<i] = 0;
q.push({0, {cu, 1<<i}});
}
for(int i=0; i<m; i++){
ll fr, to, co; cin >> fr >> to >> co;
k[fr].pb({to, co});
k[to].pb({fr, co});
}
while(!q.empty()){
auto x = q.top();
q.pop();
if(x.x > di[x.y.x][x.y.y]) continue;
//cout << x.y.x << " " << bitset<3>(x.y.y) << " " << x.x << endl;
int oma = ~x.y.y;
int i = 0;
while(i < (1<<kk)){
int a = i ^ oma;
a = a & -a;
i ^= a;
i &= -a;
//cout << i << " " << x.y.y << endl;
int nm = i | x.y.y;
if(di[x.y.x][nm] > x.x + di[x.y.x][i]){
di[x.y.x][nm] = x.x + di[x.y.x][i];
q.push({di[x.y.x][nm], {x.y.x, nm}});
}
}
for(auto u : k[x.y.x]){
if(di[u.x][x.y.y] > x.x + u.y){
di[u.x][x.y.y] = x.x + u.y;
q.push({x.x+u.y, {u.x, x.y.y}});
}
}
}
ll ans = 1e16;
for(int i=1; i<=n; i++)
ans = min(ans, di[i][(1<<kk)-1]);
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
5 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1575 ms |
69148 KB |
Output is correct |
2 |
Correct |
1226 ms |
56160 KB |
Output is correct |
3 |
Correct |
691 ms |
45692 KB |
Output is correct |
4 |
Correct |
110 ms |
12672 KB |
Output is correct |
5 |
Correct |
538 ms |
50828 KB |
Output is correct |
6 |
Correct |
96 ms |
12256 KB |
Output is correct |
7 |
Correct |
8 ms |
3456 KB |
Output is correct |
8 |
Correct |
7 ms |
3200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3964 KB |
Output is correct |
2 |
Correct |
13 ms |
3648 KB |
Output is correct |
3 |
Correct |
9 ms |
3392 KB |
Output is correct |
4 |
Correct |
9 ms |
3520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3531 ms |
93832 KB |
Output is correct |
2 |
Correct |
3200 ms |
93084 KB |
Output is correct |
3 |
Correct |
2317 ms |
64200 KB |
Output is correct |
4 |
Correct |
2280 ms |
78252 KB |
Output is correct |
5 |
Correct |
408 ms |
27264 KB |
Output is correct |
6 |
Correct |
113 ms |
14960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6093 ms |
241612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |