結果

問題 No.2337 Equidistant
ユーザー tikutikuwatikutikuwa
提出日時 2023-06-02 23:03:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,011 bytes
コンパイル時間 4,634 ms
コンパイル使用メモリ 227,932 KB
実行使用メモリ 23,316 KB
最終ジャッジ日時 2023-08-28 05:31:43
合計ジャッジ時間 11,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using mint = modint998244353;
#define INF  10000000

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    Graph g(n, vector<int>(n, INF));
    rep(i, n-1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    rep(i, n)g[i][i] = 0;

    rep(k, n)
    rep(i, n)
        rep(j, n)
            g[i][j] = min(g[i][j], g[i][k] + g[k][j]);


    rep(i, q){
        int s, t; cin >> s >> t;
        s--; t--;
        int ans = 0;
        rep(j, n){
            if(j==s || j==t)continue;
            if(g[j][s] == g[j][t] && g[j][s] !=INF && g[j][t] != INF)ans++;
        }
        cout << ans << "\n";
    }


}
0