結果

問題 No.1244 Black Segment
ユーザー kk
提出日時 2021-05-05 16:31:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 205,616 KB
実行使用メモリ 8,908 KB
最終ジャッジ日時 2023-10-11 11:51:34
合計ジャッジ時間 6,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 19 ms
4,360 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 17 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 21 ms
6,728 KB
testcase_19 AC 28 ms
6,696 KB
testcase_20 AC 32 ms
6,956 KB
testcase_21 AC 31 ms
7,500 KB
testcase_22 AC 33 ms
7,192 KB
testcase_23 AC 35 ms
7,860 KB
testcase_24 AC 33 ms
7,420 KB
testcase_25 AC 30 ms
7,156 KB
testcase_26 AC 37 ms
7,740 KB
testcase_27 AC 54 ms
8,908 KB
testcase_28 AC 35 ms
7,736 KB
testcase_29 AC 42 ms
7,984 KB
testcase_30 AC 34 ms
7,212 KB
testcase_31 AC 45 ms
7,984 KB
testcase_32 AC 49 ms
8,280 KB
testcase_33 AC 44 ms
7,996 KB
testcase_34 AC 19 ms
5,880 KB
testcase_35 AC 19 ms
5,628 KB
testcase_36 AC 26 ms
6,632 KB
testcase_37 AC 32 ms
7,524 KB
testcase_38 AC 33 ms
7,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0