結果

問題 No.1153 ねこちゃんゲーム
ユーザー chocoruskchocorusk
提出日時 2020-08-09 01:30:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 408 ms / 2,500 ms
コード長 2,360 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 140,440 KB
実行使用メモリ 67,136 KB
最終ジャッジ日時 2024-04-10 10:33:01
合計ジャッジ時間 23,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,988 KB
testcase_01 AC 4 ms
10,804 KB
testcase_02 AC 5 ms
10,880 KB
testcase_03 AC 5 ms
10,716 KB
testcase_04 AC 5 ms
10,768 KB
testcase_05 AC 5 ms
11,896 KB
testcase_06 AC 5 ms
11,764 KB
testcase_07 AC 302 ms
19,408 KB
testcase_08 AC 319 ms
19,280 KB
testcase_09 AC 317 ms
19,324 KB
testcase_10 AC 312 ms
19,384 KB
testcase_11 AC 332 ms
19,332 KB
testcase_12 AC 318 ms
19,424 KB
testcase_13 AC 324 ms
19,452 KB
testcase_14 AC 313 ms
19,200 KB
testcase_15 AC 307 ms
19,448 KB
testcase_16 AC 306 ms
19,524 KB
testcase_17 AC 299 ms
19,316 KB
testcase_18 AC 295 ms
19,460 KB
testcase_19 AC 310 ms
19,344 KB
testcase_20 AC 296 ms
19,400 KB
testcase_21 AC 287 ms
19,408 KB
testcase_22 AC 310 ms
19,364 KB
testcase_23 AC 315 ms
19,496 KB
testcase_24 AC 286 ms
19,284 KB
testcase_25 AC 289 ms
19,276 KB
testcase_26 AC 285 ms
19,384 KB
testcase_27 AC 355 ms
58,700 KB
testcase_28 AC 367 ms
67,136 KB
testcase_29 AC 402 ms
62,544 KB
testcase_30 AC 408 ms
61,984 KB
testcase_31 AC 336 ms
41,048 KB
testcase_32 AC 238 ms
19,604 KB
testcase_33 AC 251 ms
19,692 KB
testcase_34 AC 243 ms
19,708 KB
testcase_35 AC 247 ms
19,640 KB
testcase_36 AC 240 ms
19,588 KB
testcase_37 AC 207 ms
18,880 KB
testcase_38 AC 146 ms
18,832 KB
testcase_39 AC 184 ms
19,676 KB
testcase_40 AC 208 ms
18,840 KB
testcase_41 AC 150 ms
18,800 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