#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
long long inf=1e18;
#define int long long
#define tak int
struct wi{
vector<pair<int,int> > Q,przed,po;
long long odl[4]={inf,inf,inf,inf};
int przed_size=0;
long long dp1=1e18,dp2=1e18;
}*w;
int t[1000000][3];
void dijkstra(int skad,int gdzie)
{
priority_queue<pair<int,int> > kolejka;
kolejka.push({0,skad});
while(!kolejka.empty())
{
pair<int,int> para=kolejka.top();
kolejka.pop();
if(w[para.second].odl[gdzie]!=1e18)
continue;
//cout<<para.second<<" "<<gdzie<<" "<<-para.first<<"\n";
w[para.second].odl[gdzie]=-para.first;
for(int i=0;i<w[para.second].Q.size();i++)
{
int kto=w[para.second].Q[i].first;
int ile=w[para.second].Q[i].second;
if(w[kto].odl[gdzie]!=1e18)
continue;
kolejka.push({para.first-ile,kto});
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,s,tt,u,v,x,y,z;
cin>>n>>m>>s>>tt>>u>>v;
w=new wi[n+3];
for(int i=1;i<=m;i++)
{
cin>>x>>y>>z;
w[x].Q.push_back({y,z});
w[y].Q.push_back({x,z});
t[i][0]=x;
t[i][1]=y;
t[i][2]=z;
}
dijkstra(s,0);
dijkstra(u,1);
dijkstra(v,2);
dijkstra(tt,3);
long long odl_s=w[tt].odl[0];
//cout<<" "<<odl_s<<"\n";
for(int i=1;i<=m;i++)
{
//cout<<w[t[i][0]].odl[0]<<" "<<w[t[i][1]].odl[0]<<" "<<i<<"\n";
if(w[t[i][0]].odl[0]==w[t[i][1]].odl[0]+t[i][2] && w[t[i][0]].odl[0]+w[t[i][0]].odl[3]==odl_s && w[t[i][1]].odl[0]+w[t[i][1]].odl[3]==odl_s)
{
w[t[i][0]].przed.push_back({t[i][1],t[i][2]});
w[t[i][1]].po.push_back({t[i][0],t[i][2]});
}
//cout<<w[t[i][0]].odl[3]<<" "<<w[t[i][1]].odl[3]<<"\n";
if(w[t[i][1]].odl[0]==w[t[i][0]].odl[0]+t[i][2] && w[t[i][0]].odl[0]+w[t[i][0]].odl[3]==odl_s && w[t[i][1]].odl[0]+w[t[i][1]].odl[3]==odl_s)
{
w[t[i][1]].przed.push_back({t[i][0],t[i][2]});
w[t[i][0]].po.push_back({t[i][1],t[i][2]});
}
}
for(int i=1;i<=n;i++)
w[i].przed_size=w[i].przed.size();
long long wynik=w[u].odl[2];
//cout<<wynik<<"\n";
queue<int> kolejka;
kolejka.push(s);
while(!kolejka.empty())
{
int x=kolejka.front();
kolejka.pop();
//cout<<x<<"\n";
for(int i=0;i<w[x].przed.size();i++)
{
int kto=w[x].przed[i].first;
w[x].dp1=min({w[x].dp1,w[kto].dp1,w[kto].odl[1]});
w[x].dp2=min({w[x].dp2,w[kto].dp2,w[kto].odl[2]});
}
//cout<<w[x].po.size()<<"\n";
wynik=min({wynik,w[x].dp1+w[x].odl[2],w[x].dp2+w[x].odl[1]});
for(int i=0;i<w[x].po.size();i++)
{
int kto=w[x].po[i].first;
w[kto].przed_size--;
if(w[kto].przed_size==0)
kolejka.push(kto);
}
}
cout<<wynik;
return 0;
}
Compilation message
commuter_pass.cpp: In function 'void dijkstra(long long int, long long int)':
commuter_pass.cpp:29:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<w[para.second].Q.size();i++)
| ~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:88:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<w[x].przed.size();i++)
| ~^~~~~~~~~~~~~~~~~~
commuter_pass.cpp:96:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i=0;i<w[x].po.size();i++)
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
427 ms |
31684 KB |
Output is correct |
2 |
Correct |
434 ms |
31344 KB |
Output is correct |
3 |
Correct |
468 ms |
31396 KB |
Output is correct |
4 |
Correct |
483 ms |
31488 KB |
Output is correct |
5 |
Correct |
458 ms |
31040 KB |
Output is correct |
6 |
Correct |
492 ms |
31756 KB |
Output is correct |
7 |
Correct |
470 ms |
31356 KB |
Output is correct |
8 |
Correct |
461 ms |
31384 KB |
Output is correct |
9 |
Correct |
474 ms |
31360 KB |
Output is correct |
10 |
Correct |
410 ms |
35788 KB |
Output is correct |
11 |
Correct |
191 ms |
24780 KB |
Output is correct |
12 |
Correct |
414 ms |
35644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
31652 KB |
Output is correct |
2 |
Correct |
468 ms |
31176 KB |
Output is correct |
3 |
Correct |
442 ms |
31196 KB |
Output is correct |
4 |
Correct |
426 ms |
31168 KB |
Output is correct |
5 |
Correct |
456 ms |
31088 KB |
Output is correct |
6 |
Correct |
435 ms |
31308 KB |
Output is correct |
7 |
Correct |
498 ms |
31420 KB |
Output is correct |
8 |
Correct |
416 ms |
31184 KB |
Output is correct |
9 |
Correct |
453 ms |
31120 KB |
Output is correct |
10 |
Correct |
448 ms |
31128 KB |
Output is correct |
11 |
Correct |
184 ms |
23972 KB |
Output is correct |
12 |
Correct |
455 ms |
35080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2760 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
42 ms |
5800 KB |
Output is correct |
5 |
Correct |
21 ms |
3388 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
476 KB |
Output is correct |
10 |
Correct |
21 ms |
3416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
476 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
427 ms |
31684 KB |
Output is correct |
2 |
Correct |
434 ms |
31344 KB |
Output is correct |
3 |
Correct |
468 ms |
31396 KB |
Output is correct |
4 |
Correct |
483 ms |
31488 KB |
Output is correct |
5 |
Correct |
458 ms |
31040 KB |
Output is correct |
6 |
Correct |
492 ms |
31756 KB |
Output is correct |
7 |
Correct |
470 ms |
31356 KB |
Output is correct |
8 |
Correct |
461 ms |
31384 KB |
Output is correct |
9 |
Correct |
474 ms |
31360 KB |
Output is correct |
10 |
Correct |
410 ms |
35788 KB |
Output is correct |
11 |
Correct |
191 ms |
24780 KB |
Output is correct |
12 |
Correct |
414 ms |
35644 KB |
Output is correct |
13 |
Correct |
473 ms |
31652 KB |
Output is correct |
14 |
Correct |
468 ms |
31176 KB |
Output is correct |
15 |
Correct |
442 ms |
31196 KB |
Output is correct |
16 |
Correct |
426 ms |
31168 KB |
Output is correct |
17 |
Correct |
456 ms |
31088 KB |
Output is correct |
18 |
Correct |
435 ms |
31308 KB |
Output is correct |
19 |
Correct |
498 ms |
31420 KB |
Output is correct |
20 |
Correct |
416 ms |
31184 KB |
Output is correct |
21 |
Correct |
453 ms |
31120 KB |
Output is correct |
22 |
Correct |
448 ms |
31128 KB |
Output is correct |
23 |
Correct |
184 ms |
23972 KB |
Output is correct |
24 |
Correct |
455 ms |
35080 KB |
Output is correct |
25 |
Correct |
21 ms |
2760 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
42 ms |
5800 KB |
Output is correct |
29 |
Correct |
21 ms |
3388 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
476 KB |
Output is correct |
34 |
Correct |
21 ms |
3416 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
476 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
417 ms |
35220 KB |
Output is correct |
41 |
Correct |
449 ms |
35648 KB |
Output is correct |
42 |
Correct |
468 ms |
35748 KB |
Output is correct |
43 |
Correct |
150 ms |
28412 KB |
Output is correct |
44 |
Correct |
168 ms |
28712 KB |
Output is correct |
45 |
Correct |
502 ms |
40996 KB |
Output is correct |
46 |
Correct |
493 ms |
40840 KB |
Output is correct |
47 |
Correct |
401 ms |
35084 KB |
Output is correct |
48 |
Correct |
177 ms |
27948 KB |
Output is correct |
49 |
Correct |
430 ms |
34680 KB |
Output is correct |
50 |
Correct |
517 ms |
38584 KB |
Output is correct |
51 |
Correct |
480 ms |
40980 KB |
Output is correct |