| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1346890 | i_love_spring | Robot (JOI21_ho_t4) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int inf = 2e9;
void solve() {
int n, m;
cin >> n >> m;
vector<ar<int, 4>> edges(m);
vector<vector<ar<int, 2>>> g(n);
for (int i = 0; i < m;i++) {
int u, v, c, w;
cin >> u >> v >> c >> w;
--u, --v;
edges[i] = {u, v, c, w};
g[u].push_back({v, i});
g[v].push_back({u, i});
}
queue<int> q;
vector<int> dist(n, inf);
d[0] = 0;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto [v, id] : g[u])
if (d[v] > d[u] + 1)
d[v] = d[u] + 1, q.push(v);
}
cout << (d[n - 1] == inf ? -1 : d[n - 1]);
}
int32_t main() {
#ifdef Behruz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}