# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873899 |
2023-11-16T02:36:44 Z |
noiaint |
Cities (BOI16_cities) |
C++17 |
|
2441 ms |
46380 KB |
#include <bits/stdc++.h>
// #define int long long
using namespace std;
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e5 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n, m, k;
vector<pair<int, int> > adj[N];
long long d[N][1 << 5];
vector<int> node;
bool vis[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> k >> m;
node.resize(k);
for (int i = 0; i < k; ++i) {
cin >> node[i];
--node[i];
}
for (int i = 0; i < m; ++i) {
int u, v, c;
cin >> u >> v >> c;
--u;
--v;
adj[u].emplace_back(v, c);
adj[v].emplace_back(u, c);
}
memset(d, 0x3f3f, sizeof d);
long long INF = d[0][0];
for (int i = 0; i < k; ++i) {
d[node[i]][1 << i] = 0;
}
for (int mask = 1; mask < bit(k); ++mask) {
for (int x = mask; x; x = (x - 1) & mask) {
int y = mask ^ x;
for (int u = 0; u < n; ++u) {
mini(d[u][mask], d[u][x] + d[u][y]);
}
}
using node = pair<long long, int>;
priority_queue<node, vector<node>, greater<node> > q;
for (int u = 0; u < n; ++u) {
if (d[u][mask] == INF) continue;
q.emplace(d[u][mask], u);
}
while (q.size()) {
long long du;
int u;
tie(du, u) = q.top(); q.pop();
if (du != d[u][mask]) continue;
for (auto [v, c] : adj[u]) {
if (mini(d[v][mask], du + c))
q.emplace(d[v][mask], v);
}
}
}
long long res = INF;
for (int u = 0; u < n; ++u)
mini(res, d[u][bit(k) - 1]);
cout << res;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27736 KB |
Output is correct |
2 |
Correct |
4 ms |
27740 KB |
Output is correct |
3 |
Correct |
4 ms |
27740 KB |
Output is correct |
4 |
Correct |
4 ms |
27740 KB |
Output is correct |
5 |
Correct |
4 ms |
27740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
45900 KB |
Output is correct |
2 |
Correct |
476 ms |
44952 KB |
Output is correct |
3 |
Correct |
276 ms |
36692 KB |
Output is correct |
4 |
Correct |
53 ms |
36164 KB |
Output is correct |
5 |
Correct |
221 ms |
44284 KB |
Output is correct |
6 |
Correct |
45 ms |
35924 KB |
Output is correct |
7 |
Correct |
6 ms |
27992 KB |
Output is correct |
8 |
Correct |
5 ms |
27992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
27996 KB |
Output is correct |
2 |
Correct |
7 ms |
27996 KB |
Output is correct |
3 |
Correct |
6 ms |
27740 KB |
Output is correct |
4 |
Correct |
6 ms |
27996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1110 ms |
46092 KB |
Output is correct |
2 |
Correct |
1065 ms |
45184 KB |
Output is correct |
3 |
Correct |
692 ms |
36724 KB |
Output is correct |
4 |
Correct |
521 ms |
41472 KB |
Output is correct |
5 |
Correct |
117 ms |
37328 KB |
Output is correct |
6 |
Correct |
53 ms |
37396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2357 ms |
45900 KB |
Output is correct |
2 |
Correct |
2441 ms |
46380 KB |
Output is correct |
3 |
Correct |
2265 ms |
45184 KB |
Output is correct |
4 |
Correct |
1559 ms |
36728 KB |
Output is correct |
5 |
Correct |
956 ms |
41496 KB |
Output is correct |
6 |
Correct |
186 ms |
37372 KB |
Output is correct |
7 |
Correct |
62 ms |
37464 KB |
Output is correct |