#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define tiii tuple<int,int,int>
const int inf = 1e9+10;
const int mxn = 1e5+10;
vector<pii> paths[mxn];
vector<pii> dist[mxn];
priority_queue<tiii,vector<tiii>,greater<tiii>> pq;
ll N,M,K;
int sp[mxn];
vector<pair<int,pii>> v;
int ptr[mxn];
multiset<int> st;
set<pii> st2;
void DIJKSTRA(){
for(int i = 1;i<=K;i++){
int now = sp[i];
dist[now].push_back(make_pair(0,now));
sort(dist[now].begin(),dist[now].end());
pq.push(make_tuple(0,now,now));
}
while(!pq.empty()){
int d = get<0>(pq.top()),now = get<1>(pq.top()),f = get<2>(pq.top());
pq.pop();
bool flag = false;
for(auto &i:dist[now]){
if(i == make_pair(d,f))flag = true;
}
if(!flag)continue;
for(auto nxt:paths[now]){
if(dist[nxt.fs].size()<5||dist[nxt.fs].back().fs>=d+nxt.sc){
bool can = true;
int idx = -1;
for(int i = 0;i<dist[nxt.fs].size();i++){
if(dist[nxt.fs][i].sc == f){
if(dist[nxt.fs][i].fs<=d+nxt.sc)can = false;
else idx = i;
}
}
if(!can)continue;
if(idx == -1){
dist[nxt.fs].push_back({d+nxt.sc,f});
}
else{
dist[nxt.fs][idx].fs = d+nxt.sc;
}
sort(dist[nxt.fs].begin(),dist[nxt.fs].end());
pq.push(make_tuple(d+nxt.sc,nxt.fs,f));
while(dist[nxt.fs].size()>5)dist[nxt.fs].pop_back();
}
}
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>K;
for(int i = 1;i<=M;i++){
int a,b,c;
cin>>a>>b>>c;
paths[a].push_back(make_pair(b,c));
paths[b].push_back(make_pair(a,c));
}
for(int i = 1;i<=K;i++)cin>>sp[i];
DIJKSTRA();
/*
for(int i = 1;i<=K;i++){
cout<<sp[i]<<":";for(auto &j:dist[sp[i]])cout<<j.fs<<','<<j.sc<<' ';cout<<endl;
}
*/
for(int i = 1;i<=K;i++){
for(auto &j:dist[sp[i]]){
if(j.sc == sp[i])continue;
v.push_back(make_pair(j.fs,make_pair(sp[i],j.sc)));
}
ptr[sp[i]] = 1;
}
sort(v.begin(),v.end());
int ans = 1e9;
for(auto &i:v){
int a = i.sc.fs,b = i.sc.sc,d = i.fs;
for(int i = 1;i<ptr[a];i++)st.erase(dist[a][i].fs);
for(int i = 1;i<ptr[b];i++)st.erase(dist[b][i].fs);
if(!st.empty())ans = min(ans,*st.begin()+d);
for(int i = 1;i<ptr[a];i++)st.insert(dist[a][i].fs);
for(int i = 1;i<ptr[b];i++)st.insert(dist[b][i].fs);
ptr[a]++;
st.insert(d);
}
cout<<ans;
}
Compilation message
RelayMarathon.cpp: In function 'void DIJKSTRA()':
RelayMarathon.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0;i<dist[nxt.fs].size();i++){
| ~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
3 ms |
5736 KB |
Output is correct |
3 |
Correct |
2 ms |
5736 KB |
Output is correct |
4 |
Correct |
2 ms |
5736 KB |
Output is correct |
5 |
Correct |
2 ms |
5736 KB |
Output is correct |
6 |
Correct |
2 ms |
5736 KB |
Output is correct |
7 |
Correct |
2 ms |
5736 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
2 ms |
5736 KB |
Output is correct |
10 |
Correct |
2 ms |
5736 KB |
Output is correct |
11 |
Correct |
2 ms |
5736 KB |
Output is correct |
12 |
Correct |
2 ms |
5736 KB |
Output is correct |
13 |
Correct |
2 ms |
5796 KB |
Output is correct |
14 |
Correct |
2 ms |
5792 KB |
Output is correct |
15 |
Correct |
2 ms |
5736 KB |
Output is correct |
16 |
Correct |
2 ms |
5736 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5780 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
2 ms |
5776 KB |
Output is correct |
23 |
Correct |
2 ms |
5724 KB |
Output is correct |
24 |
Correct |
2 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 KB |
Output is correct |
26 |
Correct |
2 ms |
5724 KB |
Output is correct |
27 |
Correct |
2 ms |
5724 KB |
Output is correct |
28 |
Correct |
3 ms |
5724 KB |
Output is correct |
29 |
Correct |
2 ms |
5724 KB |
Output is correct |
30 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
3 ms |
5736 KB |
Output is correct |
3 |
Correct |
2 ms |
5736 KB |
Output is correct |
4 |
Correct |
2 ms |
5736 KB |
Output is correct |
5 |
Correct |
2 ms |
5736 KB |
Output is correct |
6 |
Correct |
2 ms |
5736 KB |
Output is correct |
7 |
Correct |
2 ms |
5736 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
2 ms |
5736 KB |
Output is correct |
10 |
Correct |
2 ms |
5736 KB |
Output is correct |
11 |
Correct |
2 ms |
5736 KB |
Output is correct |
12 |
Correct |
2 ms |
5736 KB |
Output is correct |
13 |
Correct |
2 ms |
5796 KB |
Output is correct |
14 |
Correct |
2 ms |
5792 KB |
Output is correct |
15 |
Correct |
2 ms |
5736 KB |
Output is correct |
16 |
Correct |
2 ms |
5736 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5780 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
2 ms |
5776 KB |
Output is correct |
23 |
Correct |
2 ms |
5724 KB |
Output is correct |
24 |
Correct |
2 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 KB |
Output is correct |
26 |
Correct |
2 ms |
5724 KB |
Output is correct |
27 |
Correct |
2 ms |
5724 KB |
Output is correct |
28 |
Correct |
3 ms |
5724 KB |
Output is correct |
29 |
Correct |
2 ms |
5724 KB |
Output is correct |
30 |
Correct |
2 ms |
5724 KB |
Output is correct |
31 |
Correct |
3 ms |
5724 KB |
Output is correct |
32 |
Correct |
3 ms |
5780 KB |
Output is correct |
33 |
Correct |
2 ms |
5724 KB |
Output is correct |
34 |
Correct |
2 ms |
5772 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
5 ms |
5980 KB |
Output is correct |
37 |
Correct |
6 ms |
5980 KB |
Output is correct |
38 |
Correct |
3 ms |
5724 KB |
Output is correct |
39 |
Correct |
30 ms |
9508 KB |
Output is correct |
40 |
Correct |
8 ms |
6504 KB |
Output is correct |
41 |
Correct |
3 ms |
5736 KB |
Output is correct |
42 |
Correct |
9 ms |
6568 KB |
Output is correct |
43 |
Correct |
6 ms |
5980 KB |
Output is correct |
44 |
Correct |
3 ms |
5736 KB |
Output is correct |
45 |
Correct |
2 ms |
5724 KB |
Output is correct |
46 |
Correct |
24 ms |
9564 KB |
Output is correct |
47 |
Correct |
7 ms |
6236 KB |
Output is correct |
48 |
Correct |
19 ms |
9052 KB |
Output is correct |
49 |
Correct |
21 ms |
9308 KB |
Output is correct |
50 |
Correct |
2 ms |
5724 KB |
Output is correct |
51 |
Correct |
3 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 KB |
Output is correct |
53 |
Correct |
13 ms |
7708 KB |
Output is correct |
54 |
Correct |
21 ms |
9308 KB |
Output is correct |
55 |
Correct |
3 ms |
5724 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
2 ms |
5724 KB |
Output is correct |
58 |
Correct |
30 ms |
9564 KB |
Output is correct |
59 |
Correct |
2 ms |
5724 KB |
Output is correct |
60 |
Correct |
4 ms |
5960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
13816 KB |
Output is correct |
2 |
Correct |
5 ms |
6248 KB |
Output is correct |
3 |
Correct |
2689 ms |
113732 KB |
Output is correct |
4 |
Correct |
1584 ms |
63548 KB |
Output is correct |
5 |
Correct |
517 ms |
23744 KB |
Output is correct |
6 |
Correct |
422 ms |
21664 KB |
Output is correct |
7 |
Correct |
545 ms |
28040 KB |
Output is correct |
8 |
Correct |
189 ms |
14372 KB |
Output is correct |
9 |
Correct |
352 ms |
20000 KB |
Output is correct |
10 |
Correct |
264 ms |
16888 KB |
Output is correct |
11 |
Correct |
2854 ms |
114740 KB |
Output is correct |
12 |
Correct |
237 ms |
18316 KB |
Output is correct |
13 |
Correct |
1364 ms |
57564 KB |
Output is correct |
14 |
Correct |
514 ms |
27824 KB |
Output is correct |
15 |
Correct |
2773 ms |
123336 KB |
Output is correct |
16 |
Correct |
85 ms |
12372 KB |
Output is correct |
17 |
Correct |
2065 ms |
95312 KB |
Output is correct |
18 |
Correct |
7 ms |
6464 KB |
Output is correct |
19 |
Correct |
2989 ms |
115132 KB |
Output is correct |
20 |
Correct |
545 ms |
27240 KB |
Output is correct |
21 |
Correct |
423 ms |
22860 KB |
Output is correct |
22 |
Correct |
211 ms |
16280 KB |
Output is correct |
23 |
Correct |
15 ms |
8284 KB |
Output is correct |
24 |
Correct |
2337 ms |
100388 KB |
Output is correct |
25 |
Correct |
328 ms |
21448 KB |
Output is correct |
26 |
Correct |
123 ms |
14280 KB |
Output is correct |
27 |
Correct |
293 ms |
18224 KB |
Output is correct |
28 |
Correct |
14 ms |
7260 KB |
Output is correct |
29 |
Correct |
522 ms |
26044 KB |
Output is correct |
30 |
Correct |
806 ms |
41380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
3 ms |
5736 KB |
Output is correct |
3 |
Correct |
2 ms |
5736 KB |
Output is correct |
4 |
Correct |
2 ms |
5736 KB |
Output is correct |
5 |
Correct |
2 ms |
5736 KB |
Output is correct |
6 |
Correct |
2 ms |
5736 KB |
Output is correct |
7 |
Correct |
2 ms |
5736 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
2 ms |
5736 KB |
Output is correct |
10 |
Correct |
2 ms |
5736 KB |
Output is correct |
11 |
Correct |
2 ms |
5736 KB |
Output is correct |
12 |
Correct |
2 ms |
5736 KB |
Output is correct |
13 |
Correct |
2 ms |
5796 KB |
Output is correct |
14 |
Correct |
2 ms |
5792 KB |
Output is correct |
15 |
Correct |
2 ms |
5736 KB |
Output is correct |
16 |
Correct |
2 ms |
5736 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5780 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
2 ms |
5776 KB |
Output is correct |
23 |
Correct |
2 ms |
5724 KB |
Output is correct |
24 |
Correct |
2 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 KB |
Output is correct |
26 |
Correct |
2 ms |
5724 KB |
Output is correct |
27 |
Correct |
2 ms |
5724 KB |
Output is correct |
28 |
Correct |
3 ms |
5724 KB |
Output is correct |
29 |
Correct |
2 ms |
5724 KB |
Output is correct |
30 |
Correct |
2 ms |
5724 KB |
Output is correct |
31 |
Correct |
3 ms |
5724 KB |
Output is correct |
32 |
Correct |
3 ms |
5780 KB |
Output is correct |
33 |
Correct |
2 ms |
5724 KB |
Output is correct |
34 |
Correct |
2 ms |
5772 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
5 ms |
5980 KB |
Output is correct |
37 |
Correct |
6 ms |
5980 KB |
Output is correct |
38 |
Correct |
3 ms |
5724 KB |
Output is correct |
39 |
Correct |
30 ms |
9508 KB |
Output is correct |
40 |
Correct |
8 ms |
6504 KB |
Output is correct |
41 |
Correct |
3 ms |
5736 KB |
Output is correct |
42 |
Correct |
9 ms |
6568 KB |
Output is correct |
43 |
Correct |
6 ms |
5980 KB |
Output is correct |
44 |
Correct |
3 ms |
5736 KB |
Output is correct |
45 |
Correct |
2 ms |
5724 KB |
Output is correct |
46 |
Correct |
24 ms |
9564 KB |
Output is correct |
47 |
Correct |
7 ms |
6236 KB |
Output is correct |
48 |
Correct |
19 ms |
9052 KB |
Output is correct |
49 |
Correct |
21 ms |
9308 KB |
Output is correct |
50 |
Correct |
2 ms |
5724 KB |
Output is correct |
51 |
Correct |
3 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 KB |
Output is correct |
53 |
Correct |
13 ms |
7708 KB |
Output is correct |
54 |
Correct |
21 ms |
9308 KB |
Output is correct |
55 |
Correct |
3 ms |
5724 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
2 ms |
5724 KB |
Output is correct |
58 |
Correct |
30 ms |
9564 KB |
Output is correct |
59 |
Correct |
2 ms |
5724 KB |
Output is correct |
60 |
Correct |
4 ms |
5960 KB |
Output is correct |
61 |
Correct |
138 ms |
13816 KB |
Output is correct |
62 |
Correct |
5 ms |
6248 KB |
Output is correct |
63 |
Correct |
2689 ms |
113732 KB |
Output is correct |
64 |
Correct |
1584 ms |
63548 KB |
Output is correct |
65 |
Correct |
517 ms |
23744 KB |
Output is correct |
66 |
Correct |
422 ms |
21664 KB |
Output is correct |
67 |
Correct |
545 ms |
28040 KB |
Output is correct |
68 |
Correct |
189 ms |
14372 KB |
Output is correct |
69 |
Correct |
352 ms |
20000 KB |
Output is correct |
70 |
Correct |
264 ms |
16888 KB |
Output is correct |
71 |
Correct |
2854 ms |
114740 KB |
Output is correct |
72 |
Correct |
237 ms |
18316 KB |
Output is correct |
73 |
Correct |
1364 ms |
57564 KB |
Output is correct |
74 |
Correct |
514 ms |
27824 KB |
Output is correct |
75 |
Correct |
2773 ms |
123336 KB |
Output is correct |
76 |
Correct |
85 ms |
12372 KB |
Output is correct |
77 |
Correct |
2065 ms |
95312 KB |
Output is correct |
78 |
Correct |
7 ms |
6464 KB |
Output is correct |
79 |
Correct |
2989 ms |
115132 KB |
Output is correct |
80 |
Correct |
545 ms |
27240 KB |
Output is correct |
81 |
Correct |
423 ms |
22860 KB |
Output is correct |
82 |
Correct |
211 ms |
16280 KB |
Output is correct |
83 |
Correct |
15 ms |
8284 KB |
Output is correct |
84 |
Correct |
2337 ms |
100388 KB |
Output is correct |
85 |
Correct |
328 ms |
21448 KB |
Output is correct |
86 |
Correct |
123 ms |
14280 KB |
Output is correct |
87 |
Correct |
293 ms |
18224 KB |
Output is correct |
88 |
Correct |
14 ms |
7260 KB |
Output is correct |
89 |
Correct |
522 ms |
26044 KB |
Output is correct |
90 |
Correct |
806 ms |
41380 KB |
Output is correct |
91 |
Correct |
396 ms |
19872 KB |
Output is correct |
92 |
Correct |
2934 ms |
145372 KB |
Output is correct |
93 |
Correct |
475 ms |
28512 KB |
Output is correct |
94 |
Correct |
1716 ms |
96888 KB |
Output is correct |
95 |
Correct |
6 ms |
6236 KB |
Output is correct |
96 |
Correct |
7 ms |
6420 KB |
Output is correct |
97 |
Correct |
753 ms |
38172 KB |
Output is correct |
98 |
Correct |
353 ms |
19880 KB |
Output is correct |
99 |
Correct |
366 ms |
21568 KB |
Output is correct |
100 |
Correct |
2949 ms |
149104 KB |
Output is correct |
101 |
Correct |
1304 ms |
64696 KB |
Output is correct |
102 |
Correct |
1368 ms |
65416 KB |
Output is correct |
103 |
Correct |
2360 ms |
114748 KB |
Output is correct |
104 |
Correct |
2385 ms |
125416 KB |
Output is correct |
105 |
Correct |
113 ms |
15116 KB |
Output is correct |
106 |
Correct |
2150 ms |
115484 KB |
Output is correct |
107 |
Correct |
758 ms |
44964 KB |
Output is correct |
108 |
Correct |
408 ms |
24816 KB |
Output is correct |
109 |
Correct |
17 ms |
7772 KB |
Output is correct |
110 |
Correct |
89 ms |
13228 KB |
Output is correct |
111 |
Correct |
437 ms |
25328 KB |
Output is correct |
112 |
Correct |
3117 ms |
148868 KB |
Output is correct |
113 |
Correct |
2881 ms |
149796 KB |
Output is correct |
114 |
Correct |
452 ms |
24252 KB |
Output is correct |
115 |
Correct |
1485 ms |
73152 KB |
Output is correct |
116 |
Correct |
2844 ms |
144668 KB |
Output is correct |
117 |
Correct |
2125 ms |
113560 KB |
Output is correct |
118 |
Correct |
1926 ms |
102320 KB |
Output is correct |
119 |
Correct |
2554 ms |
129280 KB |
Output is correct |
120 |
Correct |
1741 ms |
91200 KB |
Output is correct |