#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>using ordered_set = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);
//order_of_key()
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
signed main()
{
// #ifndef LOCAL
// freopen("lifeguards.in","r",stdin);
// freopen("lifeguards.out","w", stdout);
// #endif
fast
int n,m,k;
cin>>n >>m >>k;
int dis[n+1][n+1];
forr(i,1,n+1)
{
forr(j,1,n+1)
{
if (i==j) dis[i][j]=0;
else dis[i][j]=bigg;
}
}
forr(i,0,m)
{
int x,y,z;
cin>>x >>y >>z;
// a[x].pb({y,z});
// a[y].pb({x,z});
dis[x][y]=z;
dis[y][x]=z;
}
int s[k];
bool b[n+1]= { };
forr(i,0,k)
{
cin>>s[i];
b[s[i]]=1;
}
vector<pii> top3[n+1];
forr(q,1,n+1)
{
//vector<pii> cur;
forr(i,1,n+1)
{
forr(j,1,n+1)
{
if (i==j) continue;
dis[i][j]=min(dis[i][j],dis[i][q]+dis[q][j]);
}
//cout<<la<<i<<' '<<j<<' '<<dis[i][j]<<endl;
}
//if (b[i] && b[j]) cur.pb({dis[i][j],j});
// sort(all(cur));
// if(cur.sz>0) top3[i].pb(cur[0]);
// if(cur.sz>1) top3[i].pb(cur[1]);
// if(cur.sz>2) top3[i].pb(cur[2]);
}
forr(i,1,n+1)
{
vector<pii> cur;
forr(j,1,n+1)
{
if (i==j) continue;
if (b[i] && b[j]) cur.pb({dis[i][j],j});//cout<<la<<i<<' '<<j<<' '<<dis[i][j]<<endl;
}
sort(all(cur));
if(cur.sz>0) top3[i].pb(cur[0]);
if(cur.sz>1) top3[i].pb(cur[1]);
if(cur.sz>2) top3[i].pb(cur[2]);
}
int ans=bigg;
forr(i,0,k)
{
int x=s[i];
if (top3[x].sz==0) continue;
forr(j,0,k)
{
if (i==j) continue;
int y=s[j];
int cur=top3[x][0].fi;
int nope=top3[x][0].se;
if (y==nope) continue;
if (top3[y].sz==0) continue;
if (top3[y][0].se!=nope && top3[y][0].se!=x) cur+=top3[y][0].fi;
else if (top3[y].sz==1) continue;
else if (top3[y][1].se!=nope && top3[y][1].se!=x) cur+=top3[y][1].fi;
else if (top3[y].sz==2) continue;
else if (top3[y][2].se!=nope && top3[y][2].se!=x) cur+=top3[y][2].fi;
else if (top3[y].sz==3) continue;
else cur+=top3[y][3].fi;
// cout<<x<<' '<<y<<' '<<cur<<endl;
ans=min(ans,cur);
}
}
if (ans==bigg) ans/=0;
cout<<ans;
return 0;
}
Compilation message
RelayMarathon.cpp: In function 'int main()':
RelayMarathon.cpp:117:23: warning: division by zero [-Wdiv-by-zero]
117 | if (ans==bigg) ans/=0;
| ~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
352 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
352 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
107 ms |
2400 KB |
Output is correct |
32 |
Correct |
109 ms |
2420 KB |
Output is correct |
33 |
Correct |
115 ms |
2412 KB |
Output is correct |
34 |
Correct |
126 ms |
2648 KB |
Output is correct |
35 |
Correct |
110 ms |
2396 KB |
Output is correct |
36 |
Correct |
118 ms |
2644 KB |
Output is correct |
37 |
Correct |
120 ms |
2484 KB |
Output is correct |
38 |
Correct |
107 ms |
2392 KB |
Output is correct |
39 |
Correct |
119 ms |
3360 KB |
Output is correct |
40 |
Correct |
117 ms |
2640 KB |
Output is correct |
41 |
Correct |
106 ms |
2396 KB |
Output is correct |
42 |
Correct |
138 ms |
2640 KB |
Output is correct |
43 |
Correct |
110 ms |
2396 KB |
Output is correct |
44 |
Correct |
111 ms |
2420 KB |
Output is correct |
45 |
Correct |
123 ms |
2408 KB |
Output is correct |
46 |
Correct |
130 ms |
3416 KB |
Output is correct |
47 |
Correct |
113 ms |
2392 KB |
Output is correct |
48 |
Correct |
123 ms |
3268 KB |
Output is correct |
49 |
Correct |
123 ms |
3408 KB |
Output is correct |
50 |
Correct |
107 ms |
2396 KB |
Output is correct |
51 |
Correct |
111 ms |
2420 KB |
Output is correct |
52 |
Correct |
112 ms |
2416 KB |
Output is correct |
53 |
Correct |
113 ms |
2904 KB |
Output is correct |
54 |
Correct |
119 ms |
3416 KB |
Output is correct |
55 |
Correct |
107 ms |
2396 KB |
Output is correct |
56 |
Correct |
121 ms |
2644 KB |
Output is correct |
57 |
Correct |
107 ms |
2440 KB |
Output is correct |
58 |
Correct |
125 ms |
3672 KB |
Output is correct |
59 |
Correct |
106 ms |
2396 KB |
Output is correct |
60 |
Correct |
111 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
757 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
352 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
107 ms |
2400 KB |
Output is correct |
32 |
Correct |
109 ms |
2420 KB |
Output is correct |
33 |
Correct |
115 ms |
2412 KB |
Output is correct |
34 |
Correct |
126 ms |
2648 KB |
Output is correct |
35 |
Correct |
110 ms |
2396 KB |
Output is correct |
36 |
Correct |
118 ms |
2644 KB |
Output is correct |
37 |
Correct |
120 ms |
2484 KB |
Output is correct |
38 |
Correct |
107 ms |
2392 KB |
Output is correct |
39 |
Correct |
119 ms |
3360 KB |
Output is correct |
40 |
Correct |
117 ms |
2640 KB |
Output is correct |
41 |
Correct |
106 ms |
2396 KB |
Output is correct |
42 |
Correct |
138 ms |
2640 KB |
Output is correct |
43 |
Correct |
110 ms |
2396 KB |
Output is correct |
44 |
Correct |
111 ms |
2420 KB |
Output is correct |
45 |
Correct |
123 ms |
2408 KB |
Output is correct |
46 |
Correct |
130 ms |
3416 KB |
Output is correct |
47 |
Correct |
113 ms |
2392 KB |
Output is correct |
48 |
Correct |
123 ms |
3268 KB |
Output is correct |
49 |
Correct |
123 ms |
3408 KB |
Output is correct |
50 |
Correct |
107 ms |
2396 KB |
Output is correct |
51 |
Correct |
111 ms |
2420 KB |
Output is correct |
52 |
Correct |
112 ms |
2416 KB |
Output is correct |
53 |
Correct |
113 ms |
2904 KB |
Output is correct |
54 |
Correct |
119 ms |
3416 KB |
Output is correct |
55 |
Correct |
107 ms |
2396 KB |
Output is correct |
56 |
Correct |
121 ms |
2644 KB |
Output is correct |
57 |
Correct |
107 ms |
2440 KB |
Output is correct |
58 |
Correct |
125 ms |
3672 KB |
Output is correct |
59 |
Correct |
106 ms |
2396 KB |
Output is correct |
60 |
Correct |
111 ms |
2392 KB |
Output is correct |
61 |
Runtime error |
757 ms |
1048576 KB |
Execution killed with signal 9 |
62 |
Halted |
0 ms |
0 KB |
- |