#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
using namespace std;
const int MAXN = 1e5+10;
const ll INF = 1e18;
vector<pair<int,ll>> adj[MAXN],adj2[MAXN],readj[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,M; cin >> N >> M;
int S,T; cin >> S >> T;
int U,V; cin >> U >> V;
for(int i = 0;i<M;++i){
int a,b,c; cin >> a >> b >> c;
adj[a].push_back({b,c}); adj[b].push_back({a,c});
}
vector<ll> DU(N+1,INF); DU[U] = 0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; pq.push({0,U});
while(!pq.empty()){
int u = pq.top().s; ll d = pq.top().f; pq.pop();
if(d != DU[u]) continue;
for(auto p : adj[u]){
if(p.s+d < DU[p.f]){
DU[p.f] = p.s+d;
pq.push({DU[p.f],p.f});
}
}
}
vector<ll> DV(N+1,INF); DV[V] = 0; pq.push({0,V});
while(!pq.empty()){
int u = pq.top().s; ll d = pq.top().f; pq.pop();
if(d != DV[u]) continue;
for(auto p : adj[u]){
if(p.s+d < DV[p.f]){
DV[p.f] = p.s+d;
pq.push({DV[p.f],p.f});
}
}
}
vector<ll> DS(N+1,INF); DS[S] = 0; pq.push({0,S});
while(!pq.empty()){
int u = pq.top().s; ll d = pq.top().f; pq.pop();
if(d != DS[u]) continue;
for(auto p : adj[u]){
if(p.s+d < DS[p.f]){
DS[p.f] = p.s+d;
pq.push({DS[p.f],p.f});
}
}
}
vector<ll> DT(N+1,INF); DT[T] = 0; pq.push({0,T});
while(!pq.empty()){
int u = pq.top().s; ll d = pq.top().f; pq.pop();
if(d != DT[u]) continue;
for(auto p : adj[u]){
if(p.s+d < DT[p.f]){
DT[p.f] = p.s+d;
pq.push({DT[p.f],p.f});
}
}
}
vector<int> indeg(N+1,0);
for(int i = 1;i<=N;++i){
if(DT[i]+DS[i] != DS[T]) continue;
for(auto p : adj[i]){
if(DT[p.f]+DS[p.f] != DS[T]) continue;
if(DS[i]+p.s == DS[p.f]){
adj2[i].push_back({p.f,p.s});
readj[p.f].push_back({i,p.s});
}
}
}
queue<int> q; q.push(S);
vector<ll> dp(N+1,INF);
for(int i = 1;i<=N;++i){
dp[i] = DU[i];
}
ll ans = DU[V];
vector<ll> cnt(N+1,0);
while(!q.empty()){
int u = q.front(); q.pop();
ans = min(ans,dp[u]+DV[u]);
for(auto p : adj2[u]){
dp[p.f] = min(dp[p.f],dp[u]);
++cnt[p.f];
if(cnt[p.f] == readj[p.f].size()){
q.push(p.f);
}
}
}
q.push(T);
dp = vector<ll>(N+1,INF); cnt = vector<ll>(N+1,0);
for(int i = 1;i<=N;++i){
dp[i] = DU[i];
}
while(!q.empty()){
int u = q.front(); q.pop();
ans = min(ans,dp[u]+DV[u]);
for(auto p : readj[u]){
dp[p.f] = min(dp[p.f],dp[u]);
++cnt[p.f];
if(cnt[p.f] == adj2[p.f].size()){
q.push(p.f);
}
}
}
cout << ans << "\n";
return 0;
}
Compilation message
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:88:25: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if(cnt[p.f] == readj[p.f].size()){
commuter_pass.cpp:104:25: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | if(cnt[p.f] == adj2[p.f].size()){
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
27996 KB |
Output is correct |
2 |
Correct |
216 ms |
29040 KB |
Output is correct |
3 |
Correct |
222 ms |
31168 KB |
Output is correct |
4 |
Correct |
189 ms |
27852 KB |
Output is correct |
5 |
Correct |
205 ms |
30664 KB |
Output is correct |
6 |
Correct |
226 ms |
28104 KB |
Output is correct |
7 |
Correct |
214 ms |
31152 KB |
Output is correct |
8 |
Correct |
241 ms |
30656 KB |
Output is correct |
9 |
Correct |
206 ms |
27936 KB |
Output is correct |
10 |
Correct |
157 ms |
28148 KB |
Output is correct |
11 |
Correct |
82 ms |
22608 KB |
Output is correct |
12 |
Correct |
198 ms |
27960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
28876 KB |
Output is correct |
2 |
Correct |
243 ms |
28992 KB |
Output is correct |
3 |
Correct |
210 ms |
28616 KB |
Output is correct |
4 |
Correct |
266 ms |
28880 KB |
Output is correct |
5 |
Correct |
250 ms |
29152 KB |
Output is correct |
6 |
Correct |
248 ms |
30648 KB |
Output is correct |
7 |
Correct |
237 ms |
30968 KB |
Output is correct |
8 |
Correct |
223 ms |
28976 KB |
Output is correct |
9 |
Correct |
230 ms |
29128 KB |
Output is correct |
10 |
Correct |
246 ms |
29068 KB |
Output is correct |
11 |
Correct |
87 ms |
24148 KB |
Output is correct |
12 |
Correct |
224 ms |
31124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9564 KB |
Output is correct |
2 |
Correct |
2 ms |
7512 KB |
Output is correct |
3 |
Correct |
3 ms |
7768 KB |
Output is correct |
4 |
Correct |
12 ms |
10844 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
3 ms |
7508 KB |
Output is correct |
7 |
Correct |
3 ms |
7516 KB |
Output is correct |
8 |
Correct |
3 ms |
7768 KB |
Output is correct |
9 |
Correct |
3 ms |
7516 KB |
Output is correct |
10 |
Correct |
10 ms |
9196 KB |
Output is correct |
11 |
Correct |
2 ms |
7516 KB |
Output is correct |
12 |
Correct |
2 ms |
7516 KB |
Output is correct |
13 |
Correct |
2 ms |
7512 KB |
Output is correct |
14 |
Correct |
2 ms |
7516 KB |
Output is correct |
15 |
Correct |
2 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
27996 KB |
Output is correct |
2 |
Correct |
216 ms |
29040 KB |
Output is correct |
3 |
Correct |
222 ms |
31168 KB |
Output is correct |
4 |
Correct |
189 ms |
27852 KB |
Output is correct |
5 |
Correct |
205 ms |
30664 KB |
Output is correct |
6 |
Correct |
226 ms |
28104 KB |
Output is correct |
7 |
Correct |
214 ms |
31152 KB |
Output is correct |
8 |
Correct |
241 ms |
30656 KB |
Output is correct |
9 |
Correct |
206 ms |
27936 KB |
Output is correct |
10 |
Correct |
157 ms |
28148 KB |
Output is correct |
11 |
Correct |
82 ms |
22608 KB |
Output is correct |
12 |
Correct |
198 ms |
27960 KB |
Output is correct |
13 |
Correct |
210 ms |
28876 KB |
Output is correct |
14 |
Correct |
243 ms |
28992 KB |
Output is correct |
15 |
Correct |
210 ms |
28616 KB |
Output is correct |
16 |
Correct |
266 ms |
28880 KB |
Output is correct |
17 |
Correct |
250 ms |
29152 KB |
Output is correct |
18 |
Correct |
248 ms |
30648 KB |
Output is correct |
19 |
Correct |
237 ms |
30968 KB |
Output is correct |
20 |
Correct |
223 ms |
28976 KB |
Output is correct |
21 |
Correct |
230 ms |
29128 KB |
Output is correct |
22 |
Correct |
246 ms |
29068 KB |
Output is correct |
23 |
Correct |
87 ms |
24148 KB |
Output is correct |
24 |
Correct |
224 ms |
31124 KB |
Output is correct |
25 |
Correct |
8 ms |
9564 KB |
Output is correct |
26 |
Correct |
2 ms |
7512 KB |
Output is correct |
27 |
Correct |
3 ms |
7768 KB |
Output is correct |
28 |
Correct |
12 ms |
10844 KB |
Output is correct |
29 |
Correct |
7 ms |
9052 KB |
Output is correct |
30 |
Correct |
3 ms |
7508 KB |
Output is correct |
31 |
Correct |
3 ms |
7516 KB |
Output is correct |
32 |
Correct |
3 ms |
7768 KB |
Output is correct |
33 |
Correct |
3 ms |
7516 KB |
Output is correct |
34 |
Correct |
10 ms |
9196 KB |
Output is correct |
35 |
Correct |
2 ms |
7516 KB |
Output is correct |
36 |
Correct |
2 ms |
7516 KB |
Output is correct |
37 |
Correct |
2 ms |
7512 KB |
Output is correct |
38 |
Correct |
2 ms |
7516 KB |
Output is correct |
39 |
Correct |
2 ms |
7516 KB |
Output is correct |
40 |
Correct |
224 ms |
27808 KB |
Output is correct |
41 |
Correct |
191 ms |
28104 KB |
Output is correct |
42 |
Correct |
184 ms |
28104 KB |
Output is correct |
43 |
Correct |
110 ms |
26512 KB |
Output is correct |
44 |
Correct |
98 ms |
26452 KB |
Output is correct |
45 |
Correct |
248 ms |
36804 KB |
Output is correct |
46 |
Correct |
285 ms |
36512 KB |
Output is correct |
47 |
Correct |
189 ms |
27596 KB |
Output is correct |
48 |
Correct |
118 ms |
26100 KB |
Output is correct |
49 |
Correct |
169 ms |
27468 KB |
Output is correct |
50 |
Correct |
239 ms |
34500 KB |
Output is correct |
51 |
Correct |
223 ms |
36828 KB |
Output is correct |