#include<bits/stdc++.h>
using namespace std;
template<class T> bool minimize(T& a, T b){
if(a>b) return a=b, true;
return false;
}
template<class T> bool maximize(T& a, T b){
if(a<b) return a=b, true;
return false;
}
#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
int n, m;
vector<pair<int, int>> g[N];
vector<int> par[N];
vector<ll> dijkstra(int st){
priority_queue<pair<ll, int>> pq;
vector<ll> d(n, -1); d[st]=0;
pq.push({0, st});
while(!pq.empty()){
ll cost; int u;
tie(cost, u)=pq.top(); pq.pop();
if(-cost!=d[u]) continue;
for(int i=0; i<g[u].size(); ++i){
int v, w; tie(v, w)=g[u][i];
if(d[v]==-1 or (d[v]>(d[u]+w))){
d[v]=d[u]+w;
pq.push({-d[v], v});
}
}
}
return d;
}
vector<ll> dijkstra_withTrace(int st){
vector<ll> d(n, -1); d[st]=0;
priority_queue<pair<ll, int>> pq;
pq.push({0, st});
while(!pq.empty()){
ll cost; int u;
tie(cost, u)=pq.top(); pq.pop();
if(-cost!=d[u]) continue;
for(int i=0; i<g[u].size(); ++i){
int v, w; tie(v, w)=g[u][i];
if(d[v]==-1 or (d[v]>d[u]+w)){
d[v]=d[u]+w;
par[v].clear(); par[v].push_back(u);
pq.push({-d[v], v});
}
else if(d[v]==d[u]+w) par[v].push_back(u);
}
}
return d;
}
void Zero_OP(){
int s, t, U, V; cin>>n>>m>>s>>t>>U>>V;
--s, --t, --U, --V;
while(m--){
int a, b, c; cin>>a>>b>>c;
--a, --b;
g[a].push_back({b, c});
g[b].push_back({a, c});
}
vector<ll> dU=dijkstra(U), dV=dijkstra(V), dS=dijkstra_withTrace(s);
ll ans=dU[V];
priority_queue<pair<ll, int>> pq;
vector<ll> d(n, -1); d[t]=dV[t];
pq.push({-d[t], t});
while(!pq.empty()){
ll cost; int u;
tie(cost, u)=pq.top(); pq.pop();
if(-cost!=d[u]) continue;
minimize(ans, d[u]+dU[u]);
for(int i=0; i<par[u].size(); ++i){
int v=par[u][i];
if(d[v]==-1 or (d[v]>min(d[u], dV[v]))){
d[v]=min(d[u], dV[v]);
pq.push({-d[v], v});
}
}
}
fill(range(d), -1); d[t]=dU[t];
pq.push({-d[t], t});
while(!pq.empty()){
ll cost; int u;
tie(cost, u)=pq.top(); pq.pop();
if(-cost!=d[u]) continue;
minimize(ans, d[u]+dV[u]);
for(int i=0; i<par[u].size(); ++i){
int v=par[u][i];
if(d[v]==-1 or (d[v]>min(d[u], dU[v]))){
d[v]=min(d[u], dU[v]);
pq.push({-d[v], v});
}
}
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
Zero_OP();
return 0;
}
Compilation message
commuter_pass.cpp: In function 'std::vector<long long int> dijkstra(int)':
commuter_pass.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0; i<g[u].size(); ++i){
| ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'std::vector<long long int> dijkstra_withTrace(int)':
commuter_pass.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0; i<g[u].size(); ++i){
| ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'void Zero_OP()':
commuter_pass.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0; i<par[u].size(); ++i){
| ~^~~~~~~~~~~~~~
commuter_pass.cpp:119:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for(int i=0; i<par[u].size(); ++i){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
20244 KB |
Output is correct |
2 |
Correct |
185 ms |
19464 KB |
Output is correct |
3 |
Correct |
193 ms |
19392 KB |
Output is correct |
4 |
Correct |
169 ms |
19456 KB |
Output is correct |
5 |
Correct |
181 ms |
19388 KB |
Output is correct |
6 |
Correct |
155 ms |
20180 KB |
Output is correct |
7 |
Correct |
170 ms |
19380 KB |
Output is correct |
8 |
Correct |
199 ms |
19508 KB |
Output is correct |
9 |
Correct |
156 ms |
19468 KB |
Output is correct |
10 |
Correct |
139 ms |
19772 KB |
Output is correct |
11 |
Correct |
59 ms |
15740 KB |
Output is correct |
12 |
Correct |
185 ms |
19500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
19636 KB |
Output is correct |
2 |
Correct |
193 ms |
19312 KB |
Output is correct |
3 |
Correct |
191 ms |
19444 KB |
Output is correct |
4 |
Correct |
175 ms |
19448 KB |
Output is correct |
5 |
Correct |
188 ms |
19320 KB |
Output is correct |
6 |
Correct |
175 ms |
19464 KB |
Output is correct |
7 |
Correct |
188 ms |
19348 KB |
Output is correct |
8 |
Correct |
175 ms |
19284 KB |
Output is correct |
9 |
Correct |
167 ms |
19424 KB |
Output is correct |
10 |
Correct |
212 ms |
19260 KB |
Output is correct |
11 |
Correct |
57 ms |
15956 KB |
Output is correct |
12 |
Correct |
154 ms |
19452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6232 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
11 ms |
7260 KB |
Output is correct |
5 |
Correct |
6 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
5164 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5172 KB |
Output is correct |
9 |
Correct |
2 ms |
5212 KB |
Output is correct |
10 |
Correct |
6 ms |
6068 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
20244 KB |
Output is correct |
2 |
Correct |
185 ms |
19464 KB |
Output is correct |
3 |
Correct |
193 ms |
19392 KB |
Output is correct |
4 |
Correct |
169 ms |
19456 KB |
Output is correct |
5 |
Correct |
181 ms |
19388 KB |
Output is correct |
6 |
Correct |
155 ms |
20180 KB |
Output is correct |
7 |
Correct |
170 ms |
19380 KB |
Output is correct |
8 |
Correct |
199 ms |
19508 KB |
Output is correct |
9 |
Correct |
156 ms |
19468 KB |
Output is correct |
10 |
Correct |
139 ms |
19772 KB |
Output is correct |
11 |
Correct |
59 ms |
15740 KB |
Output is correct |
12 |
Correct |
185 ms |
19500 KB |
Output is correct |
13 |
Correct |
192 ms |
19636 KB |
Output is correct |
14 |
Correct |
193 ms |
19312 KB |
Output is correct |
15 |
Correct |
191 ms |
19444 KB |
Output is correct |
16 |
Correct |
175 ms |
19448 KB |
Output is correct |
17 |
Correct |
188 ms |
19320 KB |
Output is correct |
18 |
Correct |
175 ms |
19464 KB |
Output is correct |
19 |
Correct |
188 ms |
19348 KB |
Output is correct |
20 |
Correct |
175 ms |
19284 KB |
Output is correct |
21 |
Correct |
167 ms |
19424 KB |
Output is correct |
22 |
Correct |
212 ms |
19260 KB |
Output is correct |
23 |
Correct |
57 ms |
15956 KB |
Output is correct |
24 |
Correct |
154 ms |
19452 KB |
Output is correct |
25 |
Correct |
8 ms |
6232 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
11 ms |
7260 KB |
Output is correct |
29 |
Correct |
6 ms |
6236 KB |
Output is correct |
30 |
Correct |
2 ms |
5164 KB |
Output is correct |
31 |
Correct |
2 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5172 KB |
Output is correct |
33 |
Correct |
2 ms |
5212 KB |
Output is correct |
34 |
Correct |
6 ms |
6068 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
165 ms |
21344 KB |
Output is correct |
41 |
Correct |
152 ms |
20552 KB |
Output is correct |
42 |
Correct |
145 ms |
20740 KB |
Output is correct |
43 |
Correct |
64 ms |
16468 KB |
Output is correct |
44 |
Correct |
82 ms |
16532 KB |
Output is correct |
45 |
Correct |
163 ms |
20344 KB |
Output is correct |
46 |
Correct |
161 ms |
20012 KB |
Output is correct |
47 |
Correct |
157 ms |
20056 KB |
Output is correct |
48 |
Correct |
81 ms |
15988 KB |
Output is correct |
49 |
Correct |
135 ms |
20872 KB |
Output is correct |
50 |
Correct |
166 ms |
20260 KB |
Output is correct |
51 |
Correct |
169 ms |
20272 KB |
Output is correct |