제출 #334317

#제출 시각아이디문제언어결과실행 시간메모리
334317VROOM_VARUNCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
407 ms28144 KiB
/* ID: varunra2 LANG: C++ TASK: pass */ #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define int long long #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e16 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions int n, m; int a, b, c, d; vector<VII> adj; vector<VII> dadj; // directed VII dst; VI da, db, dc, dd; vector<bool> vis; int ret = INF; void init() { adj.resize(n); dadj.resize(n); dst.resize(n); vis.assign(n, false); } VI dijk(int src) { VI dist(n, INF); vector<bool> vis(n, false); dist[src] = 0; priority_queue<PII, VII, greater<PII>> pq; pq.push(MP(0, src)); while (!pq.empty()) { int u = pq.top().y; pq.pop(); if (vis[u]) continue; vis[u] = true; for (auto& x : adj[u]) { if (vis[x.x]) continue; if (dist[x.x] > dist[u] + x.y) { dist[x.x] = dist[u] + x.y; pq.push(MP(dist[x.x], x.x)); } } } return dist; } void dfs(int u) { if (vis[u]) return; vis[u] = true; int val1 = dst[u].x; int val2 = dst[u].y; for (auto& x : dadj[u]) { dfs(x.x); dst[u].x = min(dst[u].x, dst[x.x].x); dst[u].y = min(dst[u].y, dst[x.x].y); } ret = min(ret, min(val1 + dst[u].y, val2 + dst[u].x)); } int longestDAG() { for (int i = 0; i < n; i++) { dst[i] = MP(dc[i], dd[i]); } // debug(dst); for (int i = 0; i < n; i++) { dfs(i); } // debug(dst); return ret; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("pass.in", "r", stdin); // freopen("pass.out", "w", stdout); // #endif cin.sync_with_stdio(0); cin.tie(0); cin >> n >> m >> a >> b >> c >> d; init(); for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; adj[u].PB(MP(v, w)); adj[v].PB(MP(u, w)); } // trav(x, adj) debug(x); a--, b--, c--, d--; da = dijk(a), db = dijk(b), dc = dijk(c), dd = dijk(d); // debug(da); // debug(db); // debug(dc); // debug(dd); int dab = da[b]; int dcd = dc[d]; rep(u, 0, n) { trav(x, adj[u]) { // is (u, v) satisfactory int v = x.x; int dist = x.y; if (dab == da[u] + db[v] + dist) dadj[u].PB(x); } } cout << longestDAG() << '\n'; return 0; }

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

commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:153:7: warning: unused variable 'dcd' [-Wunused-variable]
  153 |   int dcd = dc[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...