結果
問題 |
No.1244 Black Segment
|
ユーザー |
|
提出日時 | 2021-05-05 16:31:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 805 bytes |
コンパイル時間 | 2,119 ms |
コンパイル使用メモリ | 201,080 KB |
最終ジャッジ日時 | 2025-01-21 07:31:52 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1<<30; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, a, b; cin >> n >> m >> a >> b; --a, --b; vector<vector<int> > g(n + 1); for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; --l, r; l = min(max(l, a), b + 1); r = min(max(r, a), b + 1); if (l != r) { g[l].push_back(r); g[r].push_back(l); } } vector<int> dist(n + 1, INF); dist[a] = 0; queue<int> q; q.push(a); while (!q.empty()) { int v = q.front(); q.pop(); for (int w: g[v]) { if (dist[w] == INF) { dist[w] = dist[v] + 1; q.push(w); } } } if (dist[b + 1] == INF) cout << -1 << endl; else cout << dist[b + 1] << endl; return 0; }