結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー onakaT_TitaionakaT_Titai
提出日時 2020-03-09 19:06:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,123 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 115,672 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-26 06:13:51
合計ジャッジ時間 2,585 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 43 ms
6,784 KB
testcase_21 AC 67 ms
7,552 KB
testcase_22 AC 88 ms
8,832 KB
testcase_23 AC 95 ms
9,088 KB
testcase_24 AC 95 ms
9,600 KB
testcase_25 AC 90 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<int> connected_component;
vector<vector<int>> G;

int dfs(int crt) {
    for (int i = 0; i < G[crt].size(); i++) {
        int next_v = G[crt][i];
        if (connected_component[next_v] == -1) {
            connected_component[next_v] = connected_component[crt];
            dfs(next_v);
        }
    }
    return 0;
}

vector<int> used;
int dfs2(int crt, int start, int prev) {
    used[crt] = 1;
    for (int i = 0; i < G[crt].size(); i++) {
        int next_v = G[crt][i];
        if (next_v == start && prev != start) return 1;
        if (used[next_v] == 0) dfs2(next_v, start, crt);
    }
    return 0;
}

int main(void) {
    int N; cin >> N;
    connected_component = vector<int> (N, -1);
    G = vector<vector<int>>(N);

    for (int i = 0; i < N-1; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (connected_component[i] == -1) {
            connected_component[i] = cnt;
            dfs(i);
            cnt++;
        }
    }

    if (cnt >= 3) {
        cout << "Alice" << endl;
        return 0;
    }
    if (cnt == 1) {
        cout << "Bob" << endl;
        return 0;
    }
    if (cnt == 2) {
        int cnt[2] = {};
        for (int i = 0; i < N; i++) {
            cnt[connected_component[i]]++;
        }
        if (cnt[0] != 1 && cnt[1] != 1) {
            cout << "Alice" << endl;
            return 0;
        }

        int greater_cc = 0;
        if (cnt[0] < cnt[1]) greater_cc = 1;
        
        for (int i = 0; i < N; i++) {
            if (connected_component[i] == greater_cc) {
                used = vector<int>(N);
                if (dfs2(i, i, i)) {
                    cout << "Bob" << endl;
                } else {
                    cout << "Alice" << endl;
                }
                return 0;
            }
        }
    }
}
0