이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
author: CRISTIANO RONALDO
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
can do: find_by_order, order_of_key
__builtin_clz(x): the number of zeros at the beginning of the number
__builtin_ctz(x): the number of zeros at the end of the number
__builtin_popcount(x): the number of ones in the number
__builtin_parity(x): the parity (even or odd) of the number of ones
mt19937 rng(16);
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
*/
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pb push_back
#define lv v+v
#define rv v+v+1
#define files freopen("aa.txt", "r", stdin), freopen("aa.txt", "w", stdout)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair <long long, long long>;
using pii = pair <int,int>;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
long long mod = 998244353;
const ll N = 1e5 + 10;
const ll M = 2e5 + 10;
const ll P = 311;
const ld EPS = 1e-7;
const ll block = 450;
const ll inf = 2e18;
ll n,m,ans=inf,a[2],b[2],d[N],p[N],tmp1=inf,tmp2=inf,du[N],dv[N],dpp[N], dp[N];
set <pll> q;
queue <ll> qu;
set <ll> s[N];
bool used[N];
vector <pll> g[N];
void bfs(ll idx) {
s[0].insert(b[0]);
qu.push(0);
while(!qu.empty()) {
ll v = qu.front(); qu.pop();
if(used[v]) {
continue;
}
if(v != 0) {
ans = min(ans, dpp[v] + dp[v]);
}
used[v] = true;
//cout<<v<<" "<<idx<<" "<<dp[v]<<" "<<dpp[v]<<" "<<du[v]<<" "<<dv[v]<<"\n";
for(auto u : s[v]) {
qu.push(u);
if(idx == 0) {
dp[u] = min({dp[u], du[u], dp[v]});
}
else {
// if(u == 2) {
// cout<<u<<" "<<idx<<" "<<dv[u]<<" "<<dpp[u]<<" - ";
// }
dpp[u] = min({dpp[u], dv[u], dpp[v]});
// if(u == 2) {
// cout<<u<<" "<<idx<<" "<<dv[u]<<" "<<dpp[u]<<" \n";
// }
}
}
}
//cout<<"\n\n";
}
void sub1() {
for(ll i = 1; i<=n; i++) {
d[i] = du[i] = dv[i] = inf;
}
q.insert({0,a[0]});
d[a[0]] = 0;
while(!q.empty()) {
ll v = (*q.begin()).S; ll ttt = (*q.begin()).F; q.erase(q.begin());
if(ttt > d[v]) {continue;}
for(auto u : g[v]) {
ll bb = u.F; ll w = u.S;
if (d[v]+w < d[bb]) {
d[bb] = d[v]+w;
q.insert({d[bb],bb});
s[bb].clear();
s[bb].insert(v);
}
else if(d[v]+w == d[bb]) {
s[bb].insert(v);
}
}
}
q.insert({0,a[1]});
du[a[1]] = 0;
dv[b[1]] = 0;
while(!q.empty()) {
ll v = (*q.begin()).S; ll ttt = (*q.begin()).F; q.erase(q.begin());
if(ttt > du[v]) {continue;}
for(auto u : g[v]) {
ll bb = u.F; ll w = u.S;
if (du[v]+w < du[bb]) {
du[bb] = du[v]+w;
q.insert({du[bb],bb});
}
}
}
q.insert({0,b[1]});
while(!q.empty()) {
ll v = (*q.begin()).S; ll ttt = (*q.begin()).F; q.erase(q.begin());
if(ttt > dv[v]) {continue;}
for(auto u : g[v]) {
ll bb = u.F; ll w = u.S;
if (dv[v]+w < dv[bb]) {
dv[bb] = dv[v]+w;
q.insert({dv[bb],bb});
}
}
}
bfs(0);
for(ll i = 0; i<=n; ++i) {
used[i] = false;
}
bfs(1);
cout<<min({ans, du[b[1]], dv[a[1]]});
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>m;
cin>>a[0]>>b[0]>>a[1]>>b[1];
for(ll i = 1,xxx,yyy,zzz; i<=m; i++) {
cin>>xxx>>yyy>>zzz;
g[xxx].pb({yyy,zzz});
g[yyy].pb({xxx,zzz});
}
for(ll j = 0; j<=n; j++) {
dpp[j] =dp[j]= inf;
}
sub1();
return 0;
}
// equal, min, max, 1, random, build
/*
*/
# | 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... |