# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
492867 |
2021-12-09T11:52:28 Z |
LastRonin |
Cities (BOI16_cities) |
C++14 |
|
6000 ms |
187176 KB |
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld double
#define pild pair<double,double>
using namespace std;
const ll N = 1e5 + 11;
const ll M = 32;
const ll mod = 998244353;
mt19937_64 bruh(chrono::steady_clock::now().time_since_epoch().count());
ll n, m, k;
ll dp[N][M];
set<pair<ll, pill>> pd;
vector<pill> g[N];
ll x[N];
int main() {
speed;
cin >> n >> k >> m;
for(int i = 0; i < k; i++)
cin >> x[i];
for(int i = 1; i <= m; i++) {
ll a, b, c;
cin >> a >> b >> c;
g[a].pb(mp(b, c));
g[b].pb(mp(a, c));
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j < (1<<k); j++)
dp[i][j] = 1e17;
pd.insert(mp(0, mp(i, 0)));
}
for(int i = 0; i < k; i++) {
dp[x[i]][1<<i] = 0;
pd.insert(mp(0, mp(x[i], 1<<i)));
}
while(pd.size()) {
pill v = (*pd.begin()).s;
pd.erase(pd.begin());
for(auto u : g[v.f]) {
for(int msk = 0; msk < (1<<k); msk++) {
if(!(msk&v.s)) {
if(dp[u.f][msk|v.s] > dp[u.f][msk] + u.s + dp[v.f][v.s]) {
if(dp[u.f][msk|v.s] != 1e17)
pd.erase(mp(dp[u.f][msk|v.s], mp(u.f, msk|v.s)));
dp[u.f][msk|v.s] = dp[u.f][msk] + u.s + dp[v.f][v.s];
pd.insert(mp(dp[u.f][msk|v.s], mp(u.f, msk | v.s)));
}
}
}
}
}
ll ans = 1e17;
for(int i = 1; i <= n; i++)
ans = min(ans, dp[i][(1<<k) - 1]);
cout << ans;
}
/*
5 3 1
1 2 4 7 11
5 7 10
1 3 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2676 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2680 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2917 ms |
64276 KB |
Output is correct |
2 |
Correct |
2213 ms |
59508 KB |
Output is correct |
3 |
Correct |
573 ms |
39236 KB |
Output is correct |
4 |
Correct |
117 ms |
11840 KB |
Output is correct |
5 |
Correct |
740 ms |
46496 KB |
Output is correct |
6 |
Correct |
75 ms |
11752 KB |
Output is correct |
7 |
Correct |
8 ms |
3276 KB |
Output is correct |
8 |
Correct |
4 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
3720 KB |
Output is correct |
2 |
Correct |
19 ms |
3600 KB |
Output is correct |
3 |
Correct |
10 ms |
3124 KB |
Output is correct |
4 |
Correct |
14 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6017 ms |
106692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6041 ms |
187176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |