# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
967499 |
2024-04-22T09:09:14 Z |
vjudge1 |
Cities (BOI16_cities) |
C++17 |
|
1735 ms |
79148 KB |
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Cities"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r)(rng);
}
int n, k, m;
int imp[maxn];
ll dp[35][maxn];
vector<pair<int, ll>> edges[maxn];
void DJK(ll dp[maxn])
{
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>> > q;
fi(i, 1, n) q.push({dp[i], i});
while(!q.empty())
{
ll u = q.top().second, g = q.top().first; q.pop();
if(g > dp[u]) continue;
for(auto [v, w] : edges[u]) {
if(dp[u] + w < dp[v]) {
dp[v] = dp[u] + w, q.push({dp[v], v});
}
}
}
}
void solve()
{
cin >> n >> k >> m;
fi(i, 1, k) cin >> imp[i];
fi(i, 1, m) {
int x, y, w; cin >> x >> y >> w;
edges[x].push_back({y, w}), edges[y].push_back({x, w});
}
memset(dp, 60, sizeof dp);
fi(i, 1, k) dp[(1 << (i - 1))][imp[i]] = 0;
fi(x, 1, (1 << k) - 1) {
fi(i, 1, n) for(int y = x; y > 0; y = (y - 1) & x) dp[x][i] = min(dp[x][i], dp[x ^ y][i] + dp[y][i]);
DJK(dp[x]);
}
cout << *min_element(dp[(1 << k) - 1] + 1, dp[(1 << k) - 1] + 1 + n);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
cities.cpp: In function 'int main()':
cities.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
59992 KB |
Output is correct |
2 |
Correct |
8 ms |
59996 KB |
Output is correct |
3 |
Correct |
9 ms |
60088 KB |
Output is correct |
4 |
Correct |
8 ms |
59996 KB |
Output is correct |
5 |
Correct |
8 ms |
60064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
79148 KB |
Output is correct |
2 |
Correct |
423 ms |
76444 KB |
Output is correct |
3 |
Correct |
254 ms |
69204 KB |
Output is correct |
4 |
Correct |
54 ms |
69124 KB |
Output is correct |
5 |
Correct |
221 ms |
78428 KB |
Output is correct |
6 |
Correct |
53 ms |
69116 KB |
Output is correct |
7 |
Correct |
11 ms |
60252 KB |
Output is correct |
8 |
Correct |
9 ms |
60320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
60252 KB |
Output is correct |
2 |
Correct |
12 ms |
60504 KB |
Output is correct |
3 |
Correct |
11 ms |
59996 KB |
Output is correct |
4 |
Correct |
11 ms |
60252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
876 ms |
78580 KB |
Output is correct |
2 |
Correct |
877 ms |
76516 KB |
Output is correct |
3 |
Correct |
537 ms |
69088 KB |
Output is correct |
4 |
Correct |
456 ms |
74340 KB |
Output is correct |
5 |
Correct |
131 ms |
70652 KB |
Output is correct |
6 |
Correct |
61 ms |
71724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1652 ms |
76984 KB |
Output is correct |
2 |
Correct |
1735 ms |
77584 KB |
Output is correct |
3 |
Correct |
1598 ms |
77088 KB |
Output is correct |
4 |
Correct |
1106 ms |
69244 KB |
Output is correct |
5 |
Correct |
866 ms |
74348 KB |
Output is correct |
6 |
Correct |
193 ms |
70952 KB |
Output is correct |
7 |
Correct |
69 ms |
71500 KB |
Output is correct |