제출 #210382

#제출 시각아이디문제언어결과실행 시간메모리
210382SamAndCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
450 ms33580 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 200005; struct ban { int x; long long d; ban(){} ban(int x, long long d) { this->x = x; this->d = d; } }; bool operator<(const ban& a, const ban& b) { return a.d > b.d; } int n, m; int s, t; int u, v; vector<ban> a[N]; long long ds[N], dt[N], du[N], dv[N]; bool c[N]; void djk(int x, long long d[]) { memset(c, false, sizeof c); priority_queue<ban> q; q.push(ban(x, 0)); while (1) { ban t; do { if (q.empty()) return; t = q.top(); q.pop(); } while(c[t.x]); c[t.x] = true; d[t.x] = t.d; for (int i = 0; i < a[t.x].size(); ++i) { ban h = a[t.x][i]; h.d += t.d; if (!c[h.x]) q.push(h); } } } vector<int> g[N]; long long ans; long long minu[N], minv[N]; void dfs(int x) { if (c[x]) return; c[x] = true; minu[x] = du[x]; minv[x] = dv[x]; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; dfs(h); minu[x] = min(minu[x], minu[h]); minv[x] = min(minv[x], minv[h]); } ans = min(ans, minu[x] + dv[x]); ans = min(ans, minv[x] + du[x]); } int main() { scanf("%d%d", &n, &m); scanf("%d%d", &s, &t); scanf("%d%d", &v, &u); for (int i = 0; i < m; ++i) { int x, y, d; scanf("%d%d%d", &x, &y, &d); a[x].push_back(ban(y, d)); a[y].push_back(ban(x, d)); } djk(s, ds); djk(t, dt); djk(u, du); djk(v, dv); for (int x = 1; x <= n; ++x) { for (int i = 0; i < a[x].size(); ++i) { ban h = a[x][i]; if (ds[x] + h.d + dt[h.x] == ds[t]) g[x].push_back(h.x); } } ans = du[v]; memset(c, false, sizeof c); dfs(s); printf("%lld\n", ans); return 0; }

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

commuter_pass.cpp: In function 'void djk(int, long long int*)':
commuter_pass.cpp:46:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[t.x].size(); ++i)
                         ~~^~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void dfs(int)':
commuter_pass.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:97:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
commuter_pass.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
commuter_pass.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &s, &t);
     ~~~~~^~~~~~~~~~~~~~~~
commuter_pass.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &v, &u);
     ~~~~~^~~~~~~~~~~~~~~~
commuter_pass.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...