이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define NDEBUG
#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)
#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
constexpr ll INFTY = 2e18;
ll N,M,S,T,U,V;
//{to,wi}
vector<vector<pll>> road;
//to
vector<vector<ll>> dag_out;
//from
vector<vector<ll>> dag_in;
vector<ll> Vdist,Udist;
struct stat {
ll cost;
ll to;
ll from;
bool operator <(const stat& oth) const {
return cost > oth.cost;
}
};
void djiktra(ll start, vector<ll>* costs) {
priority_queue<stat> dijkstraq;
dijkstraq.push({0,start,-1});
while (!dijkstraq.empty()) {
auto [cost, curr, _] = dijkstraq.top();
dijkstraq.pop();
if ((*costs)[curr] != -1) {
assert((*costs)[curr]<=cost);
continue;
}
(*costs)[curr]=cost;
for (auto [next, wi] : road[curr])
{
dijkstraq.push({cost+wi, next, -1});
}
}
}
vector<bool> goodnode;
void dfsgood(ll node) {
goodnode[node]=true;
for (auto next : dag_in[node])
{
dfsgood(next);
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> N >> M >> S >> T >> U >> V;
S--; T--; U--; V--; // c
road.assign(N,{});
dag_out.assign(N,{});
dag_in.assign(N,{});
Vdist.assign(N,-1);
Udist.assign(N,-1);
goodnode.assign(N,false);
for (ll i = 0; i < M; ++i)
{
ll A,B,C;
cin >> A >> B >> C;
A--; B--; //c#warning
road[A].push_back({B,C});
road[B].push_back({A,C});
}
vector<ll> node_cost(N,-1);
//node_cost[S] = 0;
dbg("hmm0");
priority_queue<stat> dijkstraq;
dijkstraq.push({0,S,-1});
while (!dijkstraq.empty()) {
auto [cost, curr, prev] = dijkstraq.top();
dijkstraq.pop();
dbg(curr <<":" <<cost);
if (node_cost[curr] != -1 && cost > node_cost[curr]) {
continue;
}
dbgv(curr <<":" <<cost);
assert(node_cost[curr]==cost || node_cost[curr]==-1);
node_cost[curr] = cost;
if (prev!=-1) {
dag_out[prev].push_back(curr);
dag_in[curr].push_back(prev);
}
for (auto [next, wi] : road[curr])
{
dijkstraq.push({cost+wi, next, curr});
}
}
//throw exception();
dbg("hmm1");
dfsgood(T);
dbg("hmm2");
djiktra(V,&Vdist);
djiktra(U,&Udist);
ll outp=INFTY;
ll o2=INFTY;
dbg("hmm3");
for (ll i = 0; i < N; ++i)
{
dbg(i << ":" << Vdist[i] <<" " << Udist[i] << " " << goodnode[i]);
if (goodnode[i]) {
outp = min(outp,Vdist[i]);
o2 = min(o2,Udist[i]);
}
}
cout << outp+o2;
}
# | 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... |