結果

問題 No.1153 ねこちゃんゲーム
ユーザー ChanyuhChanyuh
提出日時 2020-08-08 11:43:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 250 ms / 2,500 ms
コード長 3,055 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 106,180 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2024-04-08 20:53:10
合計ジャッジ時間 20,378 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,984 KB
testcase_01 AC 5 ms
11,984 KB
testcase_02 AC 5 ms
12,152 KB
testcase_03 AC 5 ms
12,152 KB
testcase_04 AC 5 ms
12,152 KB
testcase_05 AC 5 ms
12,152 KB
testcase_06 AC 6 ms
12,152 KB
testcase_07 AC 196 ms
56,644 KB
testcase_08 AC 219 ms
56,568 KB
testcase_09 AC 214 ms
56,576 KB
testcase_10 AC 205 ms
56,548 KB
testcase_11 AC 196 ms
56,576 KB
testcase_12 AC 201 ms
56,568 KB
testcase_13 AC 194 ms
56,576 KB
testcase_14 AC 207 ms
56,576 KB
testcase_15 AC 209 ms
56,576 KB
testcase_16 AC 208 ms
56,576 KB
testcase_17 AC 233 ms
56,576 KB
testcase_18 AC 212 ms
56,696 KB
testcase_19 AC 204 ms
56,632 KB
testcase_20 AC 203 ms
56,704 KB
testcase_21 AC 201 ms
56,620 KB
testcase_22 AC 213 ms
56,576 KB
testcase_23 AC 209 ms
56,576 KB
testcase_24 AC 208 ms
56,576 KB
testcase_25 AC 213 ms
56,704 KB
testcase_26 AC 208 ms
56,692 KB
testcase_27 AC 250 ms
70,256 KB
testcase_28 AC 245 ms
70,528 KB
testcase_29 AC 247 ms
69,240 KB
testcase_30 AC 239 ms
69,120 KB
testcase_31 AC 239 ms
64,000 KB
testcase_32 AC 146 ms
51,404 KB
testcase_33 AC 149 ms
51,272 KB
testcase_34 AC 145 ms
51,148 KB
testcase_35 AC 142 ms
51,272 KB
testcase_36 AC 139 ms
51,404 KB
testcase_37 AC 89 ms
37,448 KB
testcase_38 AC 73 ms
37,448 KB
testcase_39 AC 79 ms
37,448 KB
testcase_40 AC 86 ms
37,444 KB
testcase_41 AC 70 ms
37,444 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void dfs2(int, int, int)’:
main.cpp:81:13: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |         dfs2(t,s,x);
      |         ~~~~^~~~~~~
main.cpp: In function ‘void solve()’:
main.cpp:125:21: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  125 |                     if(y==(dp2[a[i]]^x)){
      |                     ^~

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m;
int a[200010];
vector<int> G[200010];
int dp[200010],dp2[200010];
int p[200010];
int cnt[200010][25],cnt2[200010][25];

void dfs1(int s,int par){
    p[s]=par;
    for(int t:G[s]){
        if(par==t) continue;
        dfs1(t,s);
        cnt[s][dp[t]]+=1;
        cnt2[s][dp[t]]+=1;
    }
    rep(i,20){
        if(!cnt[s][i]) {
            dp[s]=i;
            return;
        }
    }
}

void dfs2(int s,int par,int dp_par){
    cnt2[s][dp_par]+=1;
    rep(i,20){
        if(!cnt2[s][i]){
            dp2[s]=i;
            break;
        }
    }
    for(int t:G[s]){
        if(par==t) continue;
        int x;
        rep(i,20){
            if((cnt2[s][i]-(dp[t]==i))==0){
                x=i;
                break;
            }
        }
        dfs2(t,s,x);
    }
}

void solve(){
    cin >> n >> m;
    rep(i,m) {
        cin >> a[i];
        a[i]-=1;
    }
    rep(i,n-1){
        int u,v;cin >> u >> v;u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1(0,-1);
    dfs2(0,-1,20);
    int x=0;
    rep(i,m){
        x^=dp2[a[i]];
        //cout << dp[a[i]] << endl;
    }
    if(x==0){
        cout << -1 << " " << -1 << endl;
        return;
    }
    rep(i,m){
        if((dp2[a[i]]^x)<dp2[a[i]]){
            for(int t:G[a[i]]){
                if(p[t]==a[i]){
                    if(dp[t]==(dp2[a[i]]^x)) {
                        cout << i+1 << " " << t+1 << endl;
                        return;
                    }
                }
                else{
                    cnt2[t][dp[a[i]]]-=1;
                    int y;
                    rep(j,20){
                        if(cnt2[t][j]==0) {
                            y=j;
                            break;
                        }
                    }
                    if(y==(dp2[a[i]]^x)){
                        cout << i+1 << " " << t+1 << endl;
                        return;
                    }
                }
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0