이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
// - - - - - -
// #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int>>adj[200001];
int ans = 1e18;
int dij[5][100001];
int best[100001];
vector<int>a1[100001];
vector<int>a2[100001];
signed main(){
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});
}
set<pair<int,int>>d;
for(int i = 1; i <= n; i++){
dij[0][i] = dij[1][i] = dij[2][i] = dij[3][i] = 1e18;
}
dij[0][s] = 0;
d.insert({dij[0][s], s});
while(d.size()){
auto s = *d.begin();
d.erase(s);
if(dij[0][s.second] < s.first) continue;
dij[0][s.second] = s.first;
for(auto x:adj[s.second]){
if(dij[0][s.second] + x.second < dij[0][x.first]){
best[x.first] = s.second;
dij[0][x.first] = dij[0][s.second] + x.second;
d.insert({dij[0][x.first], x.first});
}
}
}
dij[1][t] = 0;
d.insert({dij[1][t], t});
while(d.size()){
auto s = *d.begin();
d.erase(s);
if(dij[1][s.second] < s.first) continue;
dij[1][s.second] = s.first;
for(auto x:adj[s.second]){
if(dij[1][s.second] + x.second < dij[1][x.first]){
dij[1][x.first] = dij[1][s.second] + x.second;
d.insert({dij[1][x.first], x.first});
}
}
}
dij[2][v] = 0;
d.insert({dij[2][v], v});
while(d.size()){
auto s = *d.begin();
d.erase(s);
if(dij[2][s.second] < s.first) continue;
dij[2][s.second] = s.first;
for(auto x:adj[s.second]){
if(dij[2][s.second] + x.second < dij[2][x.first]){
dij[2][x.first] = dij[2][s.second] + x.second;
d.insert({dij[2][x.first], x.first});
}
}
}
dij[3][u] = 0;
d.insert({dij[3][u], u});
while(d.size()){
auto s = *d.begin();
d.erase(s);
if(dij[3][s.second] < s.first) continue;
dij[3][s.second] = s.first;
for(auto x:adj[s.second]){
if(dij[3][s.second] + x.second < dij[3][x.first]){
dij[3][x.first] = dij[3][s.second] + x.second;
d.insert({dij[3][x.first], x.first});
}
}
}
ans = dij[3][v];
vector<pair<int,int>>a1,a2;
for(int i = 1; i <= n; i++){
if(dij[0][i] + dij[1][i] != dij[0][t]) continue;
a1.push_back({dij[3][i],i});
a2.push_back({dij[2][i],i});
}
sort(a1.begin(), a1.end());
sort(a2.begin(), a2.end());
ans = min(ans,a1[0].first + a2[1].first);
ans = min(ans,a1[1].first + a2[0].first);
ans = min(ans,a1[0].first + a2[0].first);
cout << ans;
}
# | 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... |