結果
問題 | No.1244 Black Segment |
ユーザー |
![]() |
提出日時 | 2020-10-02 22:42:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,061 bytes |
コンパイル時間 | 2,057 ms |
コンパイル使用メモリ | 205,452 KB |
最終ジャッジ日時 | 2025-01-15 00:49:45 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 18 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for (int i = 0; i < (n); ++i)#define chmax(a, b) a = max(a, b)#define chmin(a, b) a = min(a, b)#define all(x) (x).begin(), (x).end()using namespace std;using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;int main() {int n, m, a, b;cin >> n >> m >> a >> b;a--;VVI to(n-a+1);rep(_, m) {int l, r;cin >> l >> r;if (r <= a) continue;l--;if (l <= a) l = 0;else l -= a;r -= a;to[l].push_back(r);to[r].push_back(l);}queue<P> q;q.emplace(0, 0);vector<bool> visited(n-a+1);visited[0] = true;while(!q.empty()) {int u, k;tie(u, k) = q.front(); q.pop();for(int v: to[u]) {if (visited[v]) continue;visited[v] = true;if (v >= b) {cout << k + 1 << endl;return 0;}q.emplace(v, k+1);}}cout << -1 << endl;}