이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*************************************
* author: Pham Huy Khanh *
*************************************/
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcount(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define endl "\n"
using namespace std;
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }
#define gogobruhbruh ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
const int MOD = 1e9 + 7;
void add(ll &a, ll b){ if ((a += b) >= MOD) a -= MOD; }
void sub(ll &a, ll b){ if ((a -= b) < 0) a += MOD; }
int muti(int a, int b){ return 1LL * a * b % MOD; }
int Pow(int a, int b){ int res = 1; for (; b; b >>= 1, a = muti(a, a)) if (b & 1) res = muti(res, a); return res; }
const int MAX = 1e5 + 7;
const int INF = 1e9 + 7;
int numNode, numEdge, s, t, a, b;
vector<pii> edge[MAX];
ll dis[MAX][4];
priority_queue<pair<ll, int>> heap;
void pfs(int u, int i){
dis[u][i] = 0;
heap.push({0, u});
while (heap.size()){
auto [cur, u] = heap.top(); heap.pop();
if (-cur > dis[u][i])
continue;
for (auto [v, cost] : edge[u]){
if (i > 1 && dis[u][i - 2] + dis[v][(i - 2) ^ 1] + cost == dis[t][0])
cost = 0;
if (minimize(dis[v][i], dis[u][i] + cost))
heap.push({-dis[v][i], v});
}
}
}
void solve(){
memset(dis, 0x3f, sizeof(dis));
pfs(s, 0); pfs(t, 1); pfs(a, 2); pfs(a, 3);
cout << min(dis[b][2], dis[b][3]);
}
void read(){
cin >> numNode >> numEdge >> s >> t >> a >> b;
FOR (i, 1, numEdge){
static int u, v, cost;
cin >> u >> v >> cost;
edge[u].eb(pii(v, cost));
edge[v].eb(pii(u, cost));
}
}
int main(){
gogobruhbruh;
file("main");
int test = 1;
// cin >> test;
while (test--)
read(),
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:28:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:79:5: note: in expansion of macro 'file'
79 | file("main");
| ^~~~
commuter_pass.cpp:28:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:79:5: note: in expansion of macro 'file'
79 | file("main");
| ^~~~
# | 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... |