이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
const ll inf = 1e15;
int n, m;
int s, t, x, y;
ll d[maxN];
ll dp[maxN];
vector <pii> adj[maxN];
vector <int> trace[maxN];
vector <int> dag[maxN];
bool visited[maxN];
int deg[maxN];
void Dijkstra(int s, vector <ll> &res, bool flag){
set <pii> S;
fill(res.begin(), res.end(), inf);
res[s] = 0;
S.insert({0, s});
while (!S.empty()){
auto r = S.begin(); S.erase(S.begin());
if (d[r->se] != r->fi) continue;
int u = r->se;
for (const pii &i: adj[u]){
int v = i.fi;
if (res[v] > res[u] + i.se){
res[v] = res[u] + i.se;
S.insert({dp[v], v});
if (flag){
trace[v].clear();
trace[v].pb(u);
}
}
else if (res[v] == res[u] + i.se && flag){
trace[v].pb(u);
}
}
}
}
void build_dag(int s){
queue <int> Q;
Q.push(s);
while (!Q.empty()){
int r = Q.front(); Q.pop();
if (visited[r]) continue;
visited[r] = 1;
for (int v: trace[r]){
if (!visited[v]){
Q.push(v);
dag[v].pb(r);
}
}
}
}
void Init(){
cin >> n >> m >> s >> t >> x >> y;
for (int i = 1; i <= m; ++i){
int u, v, w;
cin >> u >> v >> w;
adj[u].pb({v, w});
adj[v].pb({u, w});
}
vector <ll> d(n + 1), e(n + 1), f(n + 1);
Dijkstra(t, d, 1);
Dijkstra(x, e, 0);
Dijkstra(y, f, 0);
build_dag(s);
for (int i = 1; i <= n; ++i){
for (int j: dag[i]) ++deg[j];
}
queue <int> Q;
for (int i = 1; i <= n; ++i){
dp[i] = f[i];
if (!deg[i]) Q.push(i);
}
ll ans = inf;
while (!Q.empty()){
int u = Q.front(); Q.pop();
ans = min(ans, e[u] + dp[u]);
for (const int &i: dag[u]){
dp[i] = min(dp[i], dp[u]);
if (!--deg[i]){
Q.push(i);
}
}
}
cout << ans;
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |