結果

問題 No.1153 ねこちゃんゲーム
ユーザー tarattata1tarattata1
提出日時 2020-07-11 16:03:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,903 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 98,800 KB
実行使用メモリ 62,292 KB
最終ジャッジ日時 2023-08-08 12:20:23
合計ジャッジ時間 19,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 296 ms
42,512 KB
testcase_08 AC 276 ms
42,504 KB
testcase_09 WA -
testcase_10 AC 277 ms
42,508 KB
testcase_11 WA -
testcase_12 AC 285 ms
42,492 KB
testcase_13 AC 273 ms
42,528 KB
testcase_14 WA -
testcase_15 AC 278 ms
42,440 KB
testcase_16 WA -
testcase_17 AC 292 ms
43,076 KB
testcase_18 AC 304 ms
43,864 KB
testcase_19 WA -
testcase_20 AC 297 ms
45,404 KB
testcase_21 AC 309 ms
45,152 KB
testcase_22 AC 286 ms
42,976 KB
testcase_23 AC 288 ms
43,556 KB
testcase_24 AC 291 ms
43,556 KB
testcase_25 AC 304 ms
44,564 KB
testcase_26 AC 321 ms
44,592 KB
testcase_27 AC 272 ms
54,052 KB
testcase_28 AC 347 ms
62,292 KB
testcase_29 WA -
testcase_30 AC 320 ms
60,728 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 183 ms
38,060 KB
testcase_34 AC 182 ms
38,064 KB
testcase_35 AC 168 ms
38,068 KB
testcase_36 AC 178 ms
38,004 KB
testcase_37 AC 108 ms
37,712 KB
testcase_38 AC 97 ms
37,828 KB
testcase_39 AC 101 ms
37,716 KB
testcase_40 AC 111 ms
37,728 KB
testcase_41 AC 96 ms
37,776 KB
権限があれば一括ダウンロードができます

ソースコード

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 ^= ans[a[i]];
        if (max < ans[a[i]]) {
            max = ans[a[i]];
            maxi = i;
        }
    }
    if (sum == 0) {
        printf("-1 -1\n");
    }
    else {
        int target = ans[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