結果
問題 | No.2337 Equidistant |
ユーザー | SSRS |
提出日時 | 2022-08-22 05:33:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,011 bytes |
コンパイル時間 | 1,924 ms |
コンパイル使用メモリ | 175,512 KB |
実行使用メモリ | 23,024 KB |
最終ジャッジ日時 | 2024-04-28 10:55:41 |
合計ジャッジ時間 | 9,539 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 176 ms
5,376 KB |
testcase_07 | AC | 170 ms
5,376 KB |
testcase_08 | AC | 170 ms
5,376 KB |
testcase_09 | AC | 176 ms
5,376 KB |
testcase_10 | AC | 172 ms
5,376 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, Q; cin >> N >> Q; vector<vector<int>> E(N); for (int i = 0; i < N - 1; i++){ int U, V; cin >> U >> V; U--; V--; E[U].push_back(V); E[V].push_back(U); } for (int i = 0; i < Q; i++){ int X, Y; cin >> X >> Y; X--; Y--; vector<int> d1(N, -1); d1[X] = 0; queue<int> Q1; Q1.push(X); while (!Q1.empty()){ int v = Q1.front(); Q1.pop(); for (int w : E[v]){ if (d1[w] == -1){ d1[w] = d1[v] + 1; Q1.push(w); } } } vector<int> d2(N, -1); d2[Y] = 0; queue<int> Q2; Q2.push(Y); while (!Q2.empty()){ int v = Q2.front(); Q2.pop(); for (int w : E[v]){ if (d2[w] == -1){ d2[w] = d2[v] + 1; Q2.push(w); } } } int ans = 0; for (int j = 0; j < N; j++){ if (d1[j] == d2[j]){ ans++; } } cout << ans << endl; } }