제출 #897202

#제출 시각아이디문제언어결과실행 시간메모리
897202duckindogCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
391 ms31692 KiB
// from duckindog wth depression #include<bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; using T = tuple<int, int, int>; const int N = 1e5 + 10; int n, m; int s, t, U, V; vector<pair<int, int>> ad[N]; int fs[N], ft[N]; int arr[N]; void sktra(int x) { memset(arr, 40, sizeof arr); priority_queue<pii, vector<pii>, greater<pii>> q; q.emplace(arr[x] = 0, x); while (q.size()) { int dis, u; tie(dis, u) = q.top(); q.pop(); if (dis != arr[u]) continue; for (auto duck : ad[u]) { int v, w; tie(v, w) = duck; if (arr[v] > dis + w) q.emplace(arr[v] = dis + w, v); } } } int answer = LLONG_MAX; int f[N][3]; void dijsktra(int x) { memset(f, 40, sizeof f); priority_queue<T, vector<T>, greater<T>> q; q.emplace(f[x][0] = 0, x, 0); while (q.size()) { int d, u, st; tie(d, u, st) = q.top(); q.pop(); if (d != f[u][st]) continue; for (auto duck : ad[u]) { int v, w; tie(v, w) = duck; bool onway = fs[u] + w + ft[v] == fs[t]; if (st != 1) { if (f[v][st] > d + w) q.emplace(f[v][st] = d + w, v, st); } if (st <= 1 && onway) { if (f[v][1] > d) q.emplace(f[v][1] = d, v, 1); } if (st == 1 && !onway) { if (f[v][2] > d + w) q.emplace(f[v][2] = d + w, v, 2); } } } } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n >> m; cin >> s >> t >> U >> V; for (int i = 1; i <= m; ++i) { int a, b, c; cin >> a >> b >> c; ad[a].push_back({b, c}); ad[b].push_back({a, c}); } sktra(s); for (int i = 1; i <= n; ++i) fs[i] = arr[i]; sktra(t); for (int i = 1; i <= n; ++i) ft[i] = arr[i]; dijsktra(U); answer = min({answer, f[V][0], f[V][1], f[V][2]}); dijsktra(V); answer = min({answer, f[U][0], f[U][1], f[U][2]}); cout << answer << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:66:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...