結果
問題 |
No.3013 ハチマキ買い星人
|
ユーザー |
![]() |
提出日時 | 2025-01-28 14:59:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 251 ms / 2,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 749 ms |
コンパイル使用メモリ | 64,076 KB |
実行使用メモリ | 18,400 KB |
最終ジャッジ日時 | 2025-01-28 15:00:06 |
合計ジャッジ時間 | 7,470 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:39:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d%d%d%lld", &n, &m, &p, &y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d%d%d", &u, &v, &w); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d%d", &di, &ei), di--; | ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3013.cc: No.3013 繝上メ繝槭く雋キ縺・弌莠コ - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using pii = pair<int,int>; using pli = pair<ll,int>; using vpii = vector<pii>; /* global variables */ vpii nbrs[MAX_N]; int es[MAX_N]; ll ds[MAX_N]; /* subroutines */ /* main */ int main() { int n, m, p; ll y; scanf("%d%d%d%lld", &n, &m, &p, &y); for (int i = 0; i < m; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); u--, v--; nbrs[u].push_back({v, w}); nbrs[v].push_back({u, w}); } for (int i = 0; i < p; i++) { int di, ei; scanf("%d%d", &di, &ei), di--; es[di] = ei; } fill(ds, ds + n, LINF); ds[0] = 0; priority_queue<pli> q; q.push({0, 0}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; for (auto [v, w]: nbrs[u]) { ll vd = ud + w; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } } ll maxh = 0; for (int u = 0; u < n; u++) if (es[u] > 0 && y > ds[u]) maxh = max(maxh, (y - ds[u]) / es[u]); printf("%lld\n", maxh); return 0; }