結果

問題 No.1153 ねこちゃんゲーム
ユーザー IKyoproIKyopro
提出日時 2020-08-07 23:05:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,002 bytes
コンパイル時間 2,594 ms
コンパイル使用メモリ 214,828 KB
実行使用メモリ 85,860 KB
最終ジャッジ日時 2023-10-25 04:16:52
合計ジャッジ時間 21,443 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 388 ms
40,708 KB
testcase_09 AC 377 ms
40,708 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 370 ms
40,972 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 385 ms
41,236 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 275 ms
41,164 KB
testcase_33 AC 278 ms
41,152 KB
testcase_34 WA -
testcase_35 AC 286 ms
41,168 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 97 ms
35,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> A(M);
    set<int> s;
    for(int i=0;i<M;i++){
        cin >> A[i];
        A[i]--;
        s.insert(A[i]);
    }
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<int> dp(N);
    
    {
        auto dfs = [&](auto&& self,int cur,int par)->void{
            bool exist = false;
            for(auto& to:g[cur]) if(to!=par){
                self(self,to,cur);
                exist |= !dp[to];
            }
            dp[cur] = exist;
        };
        dfs(dfs,0,-1);
    }
    vec<int> dp2(N);
    vvec<int> child[2];
    for(int i=0;i<2;i++) child[i] = vvec<int>(N);
    {
        auto dfs = [&](auto&& self,int cur,int par,int parg)->void{
            int n = g[cur].size();
            vec<int> L(n+1,0),R(n+1,0);
            for(int i=0;i<n;i++){
                int to = g[cur][i];
                L[i+1] = L[i] || !(to!=par? dp[to]:parg);
            }
            for(int i=n-1;i>=0;i--){
                int to = g[cur][i];
                R[i] = R[i+1] || !(to!=par? dp[to]:parg);
            }
            dp2[cur] = L[n];
            for(int i=0;i<n;i++){
                int to = g[cur][i];
                child[(to!=par? dp[to]:parg)][cur].push_back(to);
                if(to==par) continue;
                self(self,to,cur,L[i]||R[i+1]);
            }
        };
        dfs(dfs,0,-1,0);
    }

    int win = 0;
    for(int i=0;i<M;i++) win ^= dp2[A[i]];
    if(!win){
        cout << -1 << " " << -1 << "\n";
        return 0;
    }
    for(int i=0;i<M;i++){
        for(auto& x:child[!dp2[A[i]]][A[i]]){
            cout << i+1 << " " << x+1 << "\n";
            return 0;
        }
    }
}
0