結果

問題 No.1153 ねこちゃんゲーム
ユーザー tarattata1tarattata1
提出日時 2020-07-11 15:49:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,883 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 98,652 KB
実行使用メモリ 62,448 KB
最終ジャッジ日時 2023-08-08 12:16:03
合計ジャッジ時間 18,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

vector<vector<pair<int, int> > > g;   // to, edgeid
vector<int> parent;
vector<int> val;                 // val[2*i]:val for downward dir, val[2*i+1]: val for upward dir
vector<map<int, int> > z;        // z[i]: vals conter for directed edges from vertex i
vector<int> ans;                 // ans[i]: Grundy number for vertex i

int dfs(int par, int curr)
{
    parent[curr] = par;
    int i;
    for (i = 0; i < (int)g[curr].size(); i++) {
        int next = g[curr][i].first;
        int edge = g[curr][i].second;
        if (next == par) continue;

        int tmp = dfs(curr, next);
        val[edge * 2] = tmp;
        z[curr][tmp]++;
    }

    for (i = 0; i < INF; i++) {
        if (z[curr].empty()) {
            break;
        }
        auto it = z[curr].find(i);
        if (it == z[curr].end()) {
            break;
        }
    }
    return i;
}

void dfs2(int par, int curr)
{
    int i;
    for (i = 0; i < (int)g[curr].size(); i++) {
        int next = g[curr][i].first;
        int edge = g[curr][i].second;
        if (next == par) continue;

        int k;
        for (k = 0; k < INF; k++) {
            if (z[curr].empty()) {
                break;
            }
            auto it = z[curr].find(k);
            if (it == z[curr].end()) {
                break;
            }
            int num=it->second;
            if (val[edge*2]==k) num--;
            if (num < 1) {
                break;
            }
        }
        val[edge * 2 + 1] = k;
        z[next][k]++;
        dfs2(curr, next);
    }

    for (i = 0; i < INF; i++) {
        if (z[curr].empty()) {
            break;
        }
        auto it = z[curr].find(i);
        if (it == z[curr].end()) {
            break;
        }
    }
    ans[curr] = i;
    return;
}

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> a(m);
    int i;
    for (i = 0; i < m; i++) {
        scanf("%d", &a[i]); a[i]--;
    }

    g.resize(n);
    parent.resize(n);
    z.resize(n);
    ans.resize(n);
    val.resize((n-1) * 2);
    for (i = 0; i < n - 1; i++) {
        int p, q;
        scanf("%d%d", &p, &q); p--; q--;
        g[p].push_back(make_pair(q, i));
        g[q].push_back(make_pair(p, i));
    }

    int ret  = dfs(-1, 0);  
    dfs2(-1, 0);

    int sum = 0;
    int max = -1;
    int maxi = 0;
    for (i = 0; i < m; i++) {
        sum ^= a[i];
        if (max < a[i]) {
            max = a[i];
            maxi = i;
        }
    }
    if (sum == 0) {
        printf("-1 -1\n");
    }
    else {
        int target = a[maxi]-sum;
        int nextvtx = -1;
        for (i = 0; i < (int)g[a[maxi]].size(); i++) {
            int next = g[a[maxi]][i].first;
            int edge = g[a[maxi]][i].second;
            int tmpval = (next == parent[a[maxi]] ? val[2 * edge + 1] : val[2 * edge]);
            if (target == tmpval) {
                nextvtx = next;
                break;
            }
        }
        printf("%d %d\n", maxi + 1, nextvtx + 1);
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}
0