結果

問題 No.1153 ねこちゃんゲーム
ユーザー chocoruskchocorusk
提出日時 2020-08-09 01:30:57
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 281 ms / 2,500 ms
コード長 2,360 bytes
コンパイル時間 1,743 ms
使用メモリ 67,024 KB
最終ジャッジ日時 2022-11-26 07:53:42
合計ジャッジ時間 21,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
8,152 KB
testcase_01 AC 6 ms
8,120 KB
testcase_02 AC 3 ms
8,224 KB
testcase_03 AC 3 ms
8,220 KB
testcase_04 AC 4 ms
8,196 KB
testcase_05 AC 3 ms
8,236 KB
testcase_06 AC 3 ms
8,144 KB
testcase_07 AC 223 ms
19,256 KB
testcase_08 AC 227 ms
19,276 KB
testcase_09 AC 220 ms
19,172 KB
testcase_10 AC 220 ms
19,220 KB
testcase_11 AC 216 ms
19,280 KB
testcase_12 AC 218 ms
19,192 KB
testcase_13 AC 219 ms
19,192 KB
testcase_14 AC 220 ms
19,264 KB
testcase_15 AC 221 ms
19,296 KB
testcase_16 AC 217 ms
19,196 KB
testcase_17 AC 218 ms
19,232 KB
testcase_18 AC 224 ms
19,324 KB
testcase_19 AC 218 ms
19,264 KB
testcase_20 AC 226 ms
19,280 KB
testcase_21 AC 224 ms
19,304 KB
testcase_22 AC 219 ms
19,232 KB
testcase_23 AC 222 ms
19,228 KB
testcase_24 AC 224 ms
19,292 KB
testcase_25 AC 231 ms
19,228 KB
testcase_26 AC 223 ms
19,280 KB
testcase_27 AC 260 ms
58,460 KB
testcase_28 AC 281 ms
67,024 KB
testcase_29 AC 279 ms
62,452 KB
testcase_30 AC 276 ms
61,944 KB
testcase_31 AC 244 ms
40,756 KB
testcase_32 AC 188 ms
19,424 KB
testcase_33 AC 194 ms
19,364 KB
testcase_34 AC 191 ms
19,420 KB
testcase_35 AC 189 ms
19,320 KB
testcase_36 AC 181 ms
19,384 KB
testcase_37 AC 179 ms
18,788 KB
testcase_38 AC 118 ms
18,700 KB
testcase_39 AC 142 ms
19,388 KB
testcase_40 AC 167 ms
18,872 KB
testcase_41 AC 117 ms
18,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, m;
int a[200020];
vector<int> g[200020];
int dp[200020];
void dfs(int x, int p){
    set<int> st;
    for(auto y:g[x]){
        if(y==p) continue;
        dfs(y, x);
        st.insert(dp[y]);
    }
    for(int i=0; ; i++){
        if(st.find(i)==st.end()){
            dp[x]=i;
            break;
        }
    }
}
int dp2[200020];
int gr[200020];
int par[200020];
void dfs2(int x, int p){
    par[x]=p;
    map<int, int> mp;
    for(auto y:g[x]){
        if(y==p) mp[dp2[x]]++;
        else mp[dp[y]]++;
    }
    int mn;
    for(int i=0; ; i++){
        if(mp.find(i)==mp.end()){
            mn=i; break;
        }
    }
    gr[x]=mn;
    for(auto y:g[x]){
        if(y==p) continue;
        if(dp[y]>mn || mp[dp[y]]>1){
            dp2[y]=mn;
        }else{
            dp2[y]=dp[y];
        }
    }
    for(auto y:g[x]){
        if(y==p) continue;
        dfs2(y, x);
    }
}
int b[200020];
int main()
{
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>a[i]; a[i]--;
        b[a[i]]=i+1;
    }
    for(int i=0; i<n-1; i++){
        int u, v; cin>>u>>v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0, -1);
    dfs2(0, -1);
    int s=0;
    for(int i=0; i<m; i++){
        s^=gr[a[i]];
    }
    if(s==0){
        cout<<-1<<" "<<-1<<endl;
    }else{
        for(int i=0; i<n; i++){
            if(!b[i]) continue;
            for(auto y:g[i]){
                if(y==par[i]){
                    if((s^gr[i])==dp2[i]){
                        cout<<b[i]<<" "<<y+1<<endl;
                        return 0;
                    }
                }else{
                    if((s^gr[i])==dp[y]){
                        cout<<b[i]<<" "<<y+1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}
0