結果
問題 |
No.1244 Black Segment
|
ユーザー |
|
提出日時 | 2024-05-28 09:38:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 954 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 199,072 KB |
最終ジャッジ日時 | 2025-02-21 17:02:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> #define INF 1000000001LL #define MOD 1000000007LL #define long long long #define all(x) x.begin(),x.end() using namespace std; vector<int> graph[100003]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,a,b; cin >> n >> m >> a >> b; for(int i = 0; i<m; i++) { int x,y; cin >> x >> y; y++; if(x < a) x = a; if(x > b+1) x = b+1; if(y < a) y = a; if(y > b+1) y = b+1; graph[x].push_back(y); graph[y].push_back(x); } queue<int> q; vector<int> vis(n+2); q.push(a); vis[a] = 1; while(!q.empty()) { int x = q.front(); q.pop(); for(int y : graph[x]) { if(vis[y]) continue; vis[y] = vis[x]+1; q.push(y); } } cout << vis[b+1]-1 << endl; return 0; }