結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-12 23:15:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 139 ms / 2,000 ms |
| コード長 | 1,299 bytes |
| コンパイル時間 | 1,800 ms |
| コンパイル使用メモリ | 181,072 KB |
| 実行使用メモリ | 10,112 KB |
| 最終ジャッジ日時 | 2024-06-28 18:34:06 |
| 合計ジャッジ時間 | 8,279 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
struct Edge {
int to, w;
Edge(int to, int w) : to(to), w(w) {}
};
int main() {
int n, m;
cin >> n >> m;
vector<vector<Edge>> G(n);
rep(i, m) {
int s, t, d;
cin >> s >> t >> d;
s--, t--;
G[s].push_back(Edge(t, d));
G[t].push_back(Edge(s, d));
}
vector<int> weight(100005, 0);
const int INF = 1001001001;
weight[0] = INF;
priority_queue<P, vector<P>> q;
q.push({INF,0});
while(!q.empty()) {
int w = q.top().first, v = q.top().second; q.pop();
rep(j, G[v].size()) {
Edge e = G[v][j];
int nv = e.to, cost = e.w;
if (min(w, cost) > weight[nv]) {
weight[nv] = min(w,cost);
q.push({weight[nv], nv});
}
}
}
int ans_w = weight[n-1];
vector<int> dist(100004, INF);
dist[0] = 0;
queue<int> que;
que.push(0);
while(!que.empty()) {
int v = que.front(); que.pop();
rep(i, G[v].size()) {
Edge e = G[v][i];
int nv = e.to, cost = e.w;
if (dist[nv] != INF) continue;
if (cost < ans_w) continue;
dist[nv] = dist[v]+1;
que.push(nv);
}
}
int ans_d = dist[n-1];
cout << ans_w << " " << ans_d << endl;
}