結果

問題 No.1124 Earthquake Safety
ユーザー fastmathfastmath
提出日時 2020-07-22 22:48:52
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,757 bytes
コンパイル時間 7,481 ms
コンパイル使用メモリ 132,656 KB
実行使用メモリ 137,040 KB
最終ジャッジ日時 2023-09-05 03:00:15
合計ジャッジ時間 16,382 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 26 ms
4,384 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 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 2007;

int dist[N][N];
vector <int> g[N];
void dfs(int u, int p, int *dist) {
    for (int v : g[u]) {
        if (v != p) {
            dist[v] = dist[u] + 1;
            dfs(v, u, dist);
        }   
    }   
}   

const int MOD = 1000 * 1000 * 1000 + 7;
int pw[N];

int n;
int get(int u, int v, int k) {
    vector <int> a = {u, v, k};
    for (int i = 0; i < 3; ++i) {
        int u = a[i];
        int v = a[(i + 1) % 3];
        int k = a[(i + 2) % 3];
        if (dist[u][v] + dist[u][k] == dist[v][k]) {
            return pw[n - 1 - dist[v][k]];
        }
    }   

    int sum = (dist[u][v] + dist[v][k] + dist[u][k]) / 2;
    return pw[n - 1 - sum];

}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    pw[0] = 1;
    for (int i = 1; i < N; ++i)
        pw[i] = pw[i - 1] * 2 % MOD;

    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }   

    for (int i = 1; i <= n; ++i) {
        dfs(i, i, dist[i]);
    }   

    int ans = 0;
    for (int a = 1; a <= n; ++a) {
        for (int b = 1; b <= n; ++b) {
            for (int c = 1; c <= n; ++c) {
                ans += get(a, b, c);
                ans %= MOD;
            }   
        }   
    }   
    cout << ans << endl;
}
0