#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fr first
#define sc second
#define pow2(i) (1<<i)
#define eb emplace_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define FOR(_i, _s, _n) for (int _i = _s; _i <= _n; ++_i)
#define FOD(_i, _s, _n) for (int _i = _s; _i >= _n; --_i)
#define firstbit(_mask) __builtin_ctz(_mask)
#define lastbit(_mask) __builtin_clz(_mask)
#define countbit(_mask) __builtin_popcount(_mask)
int getbit(int mask, int i) {
return (mask >> i) & 1;
}
void flipbit(int &mask, int i) {
mask ^= (1 << i);
}
void setbit(int &mask, int i) {
mask |= (1 << i);
}
template <typename T> inline void read(T &x) {
x = 0; char c;
while (!isdigit(c = getchar()));
do x = x*10 + c - '0';
while (isdigit(c = getchar()));
}
template <typename T> inline void write(T x) {
if (x > 9) write(x/10);
putchar(x % 10 + 48);
}
const int dd[4]={-1, 0, 1, 0}, dc[4]={0, 1, 0, -1};
//#define PROBLEMS "RELAYMARATHON"
#ifdef PROBLEMS
#define cin fi
#define cout fo
ifstream fi (PROBLEMS".inp");
ofstream fo (PROBLEMS".out");
#endif
#define camnguyenmeow ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/* /\_/\
(= ._.)
/ >? \>$
*/
int n, m, k, c[501][501], firstnear[501], secondnear[501];
bool sp[501];
int main()
{
camnguyenmeow;
memset(c, 0x3f, sizeof(c));
cin >> n >> m >> k;
int a[k+1], x, y, z;
FOR(i, 1, m) {
cin >> x >> y >> z;
c[x][y] = c[y][x] = z;
}
FOR(i, 1, k) {
cin >> a[i];
sp[a[i]] = true;
}
FOR(i, 1, n)
FOR(u, 1, n)
FOR(v, 1, n) {
c[u][v] = min(c[u][v], c[u][i] + c[i][v]);
if (sp[v] && v != firstnear[u]) {
if (c[u][firstnear[u]] > c[u][v]) {
secondnear[u] = firstnear[u];
firstnear[u] = v;
} else if (c[u][secondnear[u]] > c[u][v])
secondnear[u] = v;
}
}
auto check = [&] (int i, int j, int k, int l) {
if (i == j || i == k || i == l || j == k || j == l || k == l) return false;
return true;
};
int ans = INT_MAX;
FOR(i, 1, k)
FOR(j, 1, k) {
if (i == j) continue;
int a1 = a[i], b1 = a[j], d1, d2;
d1 = firstnear[b1], d2 = secondnear[b1];
if (check(a1, b1, d1, d2))
ans = min(ans, c[a1][d1] + c[b1][d2]);
FOR(z, i + 1, k) {
int a2 = a[z];
if (check(a1, a2, b1, d1))
ans = min(ans, c[a1][a2] + c[b1][d1]);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
1 ms |
1260 KB |
Output is correct |
4 |
Correct |
1 ms |
1260 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
1260 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
1260 KB |
Output is correct |
12 |
Correct |
1 ms |
1260 KB |
Output is correct |
13 |
Correct |
3 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1388 KB |
Output is correct |
15 |
Correct |
2 ms |
1388 KB |
Output is correct |
16 |
Correct |
1 ms |
1260 KB |
Output is correct |
17 |
Correct |
2 ms |
1388 KB |
Output is correct |
18 |
Correct |
1 ms |
1260 KB |
Output is correct |
19 |
Correct |
2 ms |
1388 KB |
Output is correct |
20 |
Correct |
1 ms |
1260 KB |
Output is correct |
21 |
Correct |
2 ms |
1388 KB |
Output is correct |
22 |
Incorrect |
1 ms |
1260 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
1 ms |
1260 KB |
Output is correct |
4 |
Correct |
1 ms |
1260 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
1260 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
1260 KB |
Output is correct |
12 |
Correct |
1 ms |
1260 KB |
Output is correct |
13 |
Correct |
3 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1388 KB |
Output is correct |
15 |
Correct |
2 ms |
1388 KB |
Output is correct |
16 |
Correct |
1 ms |
1260 KB |
Output is correct |
17 |
Correct |
2 ms |
1388 KB |
Output is correct |
18 |
Correct |
1 ms |
1260 KB |
Output is correct |
19 |
Correct |
2 ms |
1388 KB |
Output is correct |
20 |
Correct |
1 ms |
1260 KB |
Output is correct |
21 |
Correct |
2 ms |
1388 KB |
Output is correct |
22 |
Incorrect |
1 ms |
1260 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2540 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
1 ms |
1260 KB |
Output is correct |
4 |
Correct |
1 ms |
1260 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
1260 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
1260 KB |
Output is correct |
12 |
Correct |
1 ms |
1260 KB |
Output is correct |
13 |
Correct |
3 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1388 KB |
Output is correct |
15 |
Correct |
2 ms |
1388 KB |
Output is correct |
16 |
Correct |
1 ms |
1260 KB |
Output is correct |
17 |
Correct |
2 ms |
1388 KB |
Output is correct |
18 |
Correct |
1 ms |
1260 KB |
Output is correct |
19 |
Correct |
2 ms |
1388 KB |
Output is correct |
20 |
Correct |
1 ms |
1260 KB |
Output is correct |
21 |
Correct |
2 ms |
1388 KB |
Output is correct |
22 |
Incorrect |
1 ms |
1260 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |