이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair < int, int >
#define pii pair < int, pair < int, int >>
#define endl "\n"
#define debug cout << "AXD" << endl; return 0;
#define pb push_back
#define F first
#define S second
const int MAXN = 1e5 + 5;
int n, m;
int s, t, u, v;
vector < pi > adj[MAXN];
vector < int > dist ( MAXN, 1e18);
vector < int > from ( MAXN, -1);
map < pi, bool > mp;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for ( int i = 1; i <= m; i++){
int x1, x2, x3; cin >> x1 >> x2 >> x3;
adj[x1].pb({x2, x3});
adj[x2].pb({x1, x3});
}
// subsoal 2
priority_queue < pi, vector < pi > , greater < pi > > pq;
dist[s] = 0;
pq.push({0, s});
while ( !pq.empty()){
int val = pq.top().F, par = pq.top().S;
pq.pop();
if ( val > dist[par] ) continue;
for ( auto [child, weight] : adj[par] ){
if ( dist[par] + weight < dist[child]){
dist[child] = dist[par] + weight;
from[child] = par;
pq.push({dist[child], child});
}
}
}
int temp = t;
while ( temp != s ){
mp[{temp, from[temp]}] = 1;
mp[{from[temp], temp}] = 1;
temp = from[temp];
}
dist.resize(MAXN, 1e18);
priority_queue < pi, vector < pi > , greater < pi > > pyqe;
dist[u] = 0;
pq.push({0, u});
while ( !pq.empty()){
int val = pq.top().F, par = pq.top().S;
pq.pop();
if ( val > dist[par] ) continue;
for ( auto [child, weight] : adj[par] ){
if ( mp.count({child, par}) ) weight = 0;
if ( dist[par] + weight < dist[child]){
dist[child] = dist[par] + weight;
from[child] = par;
pq.push({dist[child], child});
}
}
}
cout << dist[v] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |