結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
|
提出日時 | 2021-04-09 22:51:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 231 ms / 2,000 ms |
コード長 | 2,211 bytes |
コンパイル時間 | 2,039 ms |
コンパイル使用メモリ | 194,004 KB |
実行使用メモリ | 32,140 KB |
最終ジャッジ日時 | 2024-06-25 06:33:42 |
合計ジャッジ時間 | 10,192 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll = long long; const int INF = 1 << 30; void Main() { int n, m; cin >> n >> m; vector<map<int, int>> graph(n, map<int, int>()); for (int i = 0; i < m; ++i) { int s, t, d; cin >> s >> t >> d; --s; --t; if (graph[s].count(t) == 0) { graph[s].insert(make_pair(t, d)); graph[t].insert(make_pair(s, d)); } else { graph[s][t] = max(graph[s][t], d); graph[t][s] = max(graph[t][s], d); } } typedef pair<int, int> weight_curr; priority_queue<weight_curr, vector<weight_curr>> q; vector<int> w(n, -1); int start = 0; q.push(make_pair(INF, start)); w[start] = INF; while (!q.empty()) { int weight = q.top().first; int curr = q.top().second; q.pop(); if (w[curr] > weight) { continue; } for (auto edge : graph[curr]) { int to = edge.first; int wei = edge.second; if (w[to] < min(w[curr], wei)) { w[to] = min(w[curr], wei); q.push(make_pair(w[to], to)); } } } int maxWeight = w[n - 1]; vector<set<int>> allowed(n, set<int>()); for (int i = 0; i < n; ++i) { for (auto e : graph[i]) { if (e.second >= maxWeight) { allowed[i].insert(e.first); } } } typedef pair<int, int> dist_curr; priority_queue<dist_curr, vector<dist_curr>, greater<dist_curr>> aq; vector<int> d(n, INF); aq.push(make_pair(0, start)); d[start] = 0; while (!aq.empty()) { int dist = aq.top().first; int curr = aq.top().second; aq.pop(); if (d[curr] < dist) { continue; } for (auto to : allowed[curr]) { if (d[to] > d[curr] + 1) { d[to] = d[curr] + 1; aq.push(make_pair(d[to], to)); } } } int minPath = d[n - 1]; cout << maxWeight << " " << minPath << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }