이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName "test"
#define ll long long
#define ld long double
#define ull unsigned long long
#define Print(x) cerr << #x << "is " << x << '\n';
#define pb push_back
#define X first
#define Y second
//#define Karma
using namespace std;
template<typename T> inline void Cin(T &x)
{
char c;
T sign = 1;
x = 0;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') sign = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 1e5 + 7;
const ll oo = (ll)1e18 + 7;
struct TEdge
{
int u, v; ll w;
} _e[N * 2];
typedef TEdge* PEdge;
PEdge e;
ll res;
queue<int> q;
vector<ll> d[4], dis[4];
vector<int> g[N];
vector<PEdge> a[N];
int n, m, s, t, u, v, in[N];
priority_queue<plli, vector<plli>, greater<plli>> pq;
void Dijkstra(int s, vector<ll>& d)
{
d.resize(n + 1);
for(int i = 0; i <= n; ++i) d[i] = oo;
pq.push({0, s});
d[s] = 0;
while(!pq.empty())
{
plli top = pq.top();
pq.pop();
if(d[top.Y] != top.X) continue;
int u = top.Y;
for(PEdge e: a[u])
{
int v = e -> u + e -> v - u;
if(d[v] > d[u] + e -> w) d[v] = d[u] + e -> w, pq.push({d[v], v});
}
}
}
void Enter()
{
Cin(n, m, s, t, u, v);
e = _e;
For(i, 1, m)
{
++e;
Cin(e -> u, e -> v, e -> w);
a[e -> u].pb(e), a[e -> v].pb(e);
}
Dijkstra(s, d[0]), Dijkstra(t, d[1]);
Dijkstra(u, d[2]), Dijkstra(v, d[3]);
e = _e;
For(i, 1, m)
{
++e;
if(d[0][e -> u] + e -> w + d[1][e -> v] == d[0][t])
g[e -> v].pb(e -> u), ++in[e -> u];
swap(e -> u, e -> v);
if(d[0][e -> u] + e -> w + d[1][e -> v] == d[0][t])
g[e -> v].pb(e -> u), ++in[e -> u];
}
}
void Solve()
{
dis[2] = d[2], dis[3] = d[3];
res = d[2][v];
q.push(t);
while(!q.empty())
{
int x = q.front();
q.pop();
res = min(res, min(d[3][x] + dis[2][x], d[2][x] + dis[3][x]));
for(int y: g[x])
{
dis[3][y] = min(dis[3][x], dis[3][y]);
dis[2][y] = min(dis[2][y], dis[2][x]);
--in[y];
if(in[y] == 0) q.push(y);
}
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef Karma
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
#endif // Karma
Enter();
Solve();
return 0;
}
# | 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... |