結果
問題 |
No.2477 Drifting
|
ユーザー |
![]() |
提出日時 | 2024-06-21 14:12:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,010 bytes |
コンパイル時間 | 1,190 ms |
コンパイル使用メモリ | 80,468 KB |
最終ジャッジ日時 | 2025-02-21 23:40:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 6 MLE * 1 -- * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%d%d%d", &u, &v, &w); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:61:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%d", &k); | ~~~~~^~~~~~~~~~ main.cpp:65:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 65 | scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2477.cc: No.2477 Drifting - yukicoder */ #include<cstdio> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_M = 200000; const int MAX_GN = MAX_N + MAX_M; const int MAX_K = 200000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using pii = pair<int,int>; using vpii = vector<pii>; using si = set<int>; using mpii = map<pii,int>; using pli = pair<ll,int>; /* global variables */ vpii es[MAX_N], nbrs[MAX_GN]; int orgs[MAX_GN]; si exs[MAX_GN]; ll ds[MAX_GN]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); u--, v--; es[u].push_back({v, w}); } for (int i = 0; i < n; i++) orgs[i] = i; int gn = n; mpii evs; int k; scanf("%d", &k); while (k--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); a--, b--, c--; auto mit = evs.find({a, b}); int u = -1; if (mit != evs.end()) u = mit->second; else { u = evs[{a, b}] = gn++; orgs[u] = b; } exs[u].insert(c); } //printf(" gn=%d\n", gn); for (int u = 0; u < gn; u++) { int ou = orgs[u]; for (auto [v, w]: es[ou]) { if (! exs[u].empty() && exs[u].find(v) != exs[u].end()) continue; auto mit = evs.find({ou, v}); if (mit != evs.end()) v = mit->second; nbrs[u].push_back({v, w}); } } evs.clear(); fill(ds, ds + gn, LINF); ds[0] = 0; priority_queue<pli> q; q.push({0, 0}); ll mind = LINF; while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; if (u == n - 1) { mind = ud; break; } for (auto [v, w]: nbrs[u]) { ll vd = ud + w; if (ds[v] > vd) { ds[v] = vd; q.push({-vd, v}); } } } printf("%lld\n", (mind < LINF) ? mind : -1LL); return 0; }