# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392003 |
2021-04-20T09:52:01 Z |
negar_a |
Cities (BOI16_cities) |
C++14 |
|
6000 ms |
54468 KB |
//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <ll, ll>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
const ll maxn = 2e5 + 5;
ll x[maxn], y[maxn], w[maxn];
ll imp[maxn], im[maxn];
vector <pii> adj[maxn], par[maxn];
ll dis[maxn][8], pm[8];
ll dp[maxn][35];
ll inf = 1e17;
ll n, m, k;
bool mark[maxn];
int main(){
fast_io;
cin >> n >> k >> m;
for(ll i = 0; i < k; i ++){
cin >> im[i];
im[i] --;
imp[im[i]] ++;
}
for(ll i = 0; i < m; i ++){
ll x, y;
cin >> x >> y >> w[i];
x --; y --;
adj[x].pb({y, i});
adj[y].pb({x, i});
}
ll ans = inf;
for(ll mask = 0; mask < (1 << k); mask ++){
for(ll i = 0; i < n; i ++){
dp[i][mask] = inf;
}
}
for(ll i = 0; i < k; i ++){
dp[im[i]][1 << i] = 0;
}
for(ll mask = 1; mask < (1 << k); mask ++){
for(ll m1 = 1; m1 < mask; m1 ++){
if((m1 & mask) == m1){
for(ll i = 0; i < n; i ++){
dp[i][mask] = min(dp[i][mask], dp[i][mask ^ m1] + dp[i][m1]);
}
}
}
priority_queue <pii> s;
for(ll i = 0; i < n; i ++){
if(dp[i][mask] < inf){
s.push({dp[i][mask], i});
}
}
while(s.size()){
ll we = s.top().F;
ll x = s.top().S;
s.pop();
if(dp[x][mask] == we){
for(auto u : adj[x]){
if(dp[u.F][mask] > dp[x][mask] + w[u.S]){
dp[u.F][mask] = dp[x][mask] + w[u.S];
s.push({dp[u.F][mask], u.F});
}
}
}
}
}
for(ll i = 0; i < n; i ++){
ans = min(ans, dp[i][(1 << k) - 1]);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9716 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9676 KB |
Output is correct |
5 |
Correct |
7 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6026 ms |
54412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
10208 KB |
Output is correct |
2 |
Correct |
31 ms |
10188 KB |
Output is correct |
3 |
Correct |
53 ms |
10248 KB |
Output is correct |
4 |
Correct |
47 ms |
10064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6099 ms |
54444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6062 ms |
54468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |