# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
475464 |
2021-09-22T14:45:09 Z |
fredbr |
Cities (BOI16_cities) |
C++17 |
|
300 ms |
22132 KB |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define clr(x, c) memset((x), (c), sizeof((x)))
using namespace std;
template<class T> void DBG(T&& x) { cerr << x << " "; }
template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); }
#define DBG(...) do {cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; } while (0)
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
template<class num> inline void rd(num& x) {
char c, neg = 0; while(isspace(c = getchar_unlocked()));
if(!isdigit(c)) neg = (c == '-'), x = 0;
else x = c - '0';
while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
x = neg ? -x : x; }
template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); }
using ll = long long;
using ii = pair<ll, ll>;
using Gr = vector<vector<ii>>;
template<typename T = int>
constexpr T inf = 0x3f3f3f3f;
template<>
constexpr ll inf<ll> = 0x3f3f3f3f3f3f3f3f;
seed_seq seq {
(uint64_t) chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().
time_since_epoch()).count(),
(uint64_t) __builtin_ia32_rdtsc(),
(uint64_t) random_device{}(),
(uint64_t) 17
};
mt19937 rng{seq};
template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
vector<ll> sssp(Gr const& g, int src = 0) {
int const n = g.size();
vector<ll> dist(n, inf<ll>);
vector<char> vis(n);
priority_queue<ii, vector<ii>, greater<ii>> pq;
pq.push({0, src});
dist[src] = 0;
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (vis[u]) continue;
vis[u] = 1;
for (auto [v, w] : g[u]) {
auto cost = d + w;
if (cost < dist[v]) {
dist[v] = cost;
pq.emplace(cost, v);
}
}
}
return dist;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int n, k, m;
cin >> n >> k >> m;
vector<int> cities(k);
for (auto& i : cities) cin >> i;
Gr g(n+1);
for (int i = 0; i < m; i++) {
int a, b, w;
cin >> a >> b >> w;
g[a].eb(b, w);
g[b].eb(a, w);
}
if (k <= 3) {
vector<vector<ll>> d;
for (auto src : cities) d.push_back(sssp(g, src));
ll ans = inf<ll>;
for (int i = 1; i <= n; i++) {
ll cost = d[0][i] + d[1][i] + (k == 3? d[2][i] : 0);
ans = min(ans, cost);
}
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
284 ms |
17328 KB |
Output is correct |
2 |
Correct |
300 ms |
22132 KB |
Output is correct |
3 |
Correct |
140 ms |
12488 KB |
Output is correct |
4 |
Correct |
86 ms |
12932 KB |
Output is correct |
5 |
Correct |
262 ms |
20696 KB |
Output is correct |
6 |
Correct |
79 ms |
12796 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
133 ms |
13012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
12920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |