CF1779F.Xorcerer's Stones
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Misha had been banned from playing chess for good since he was accused of cheating with an engine. Therefore, he retired and decided to become a xorcerer.
One day, while taking a walk in a park, Misha came across a rooted tree with nodes numbered from 1 to n . The root of the tree is node 1 .
For each 1≤i≤n , node i contains ai stones in it. Misha has recently learned a new spell in his xorcery class and wants to test it out. A spell consists of:
- Choose some node i ( 1≤i≤n ).
- Calculate the bitwise XOR x of all aj such that node j is in the subtree of i ( i belongs to its own subtree).
- Set aj equal to x for all nodes j in the subtree of i .
Misha can perform at most 2n spells and he wants to remove all stones from the tree. More formally, he wants ai=0 to hold for each 1≤i≤n . Can you help him perform the spells?
A tree with n nodes is a connected acyclic graph which contains n−1 edges. The subtree of node i is the set of all nodes j such that i lies on the simple path from 1 (the root) to j . We consider i to be contained in its own subtree.
输入格式
The first line contains a single integer n ( 2≤n≤2⋅105 ) — the size of the tree
The second line contains an array of integers a1,a2,…,an ( 0≤ai≤31 ), describing the number of stones in each node initially.
The third line contains an array of integers p2,p3,…,pn ( 1≤pi≤i−1 ), where pi means that there is an edge connecting pi and i .
输出格式
If there is not a valid sequence of spells, output −1 .
Otherwise, output a single integer q ( 0≤q≤2n ) in the first line — the number of performed spells.
In the second line output a sequence of integers v1,v2,…,vq ( 1≤vi≤n ) — the i -th spell will be performed on the subtree of node vi . Please note that order matters.
If multiple solutions exist, output any. You don't have to minimize the number of operations.
输入输出样例
输入#1
2 13 13 1
输出#1
1 1
输入#2
7 5 2 8 3 4 1 31 1 1 2 2 3 3
输出#2
-1
输入#3
9 3 31 1 2 7 30 7 3 1 1 1 1 2 5 5 3 4
输出#3
6 3 2 3 1 2 2
说明/提示
Please refer to the following pictures for an explanation of the third test. Only the first 4 spells are shown since the last 2 do nothing. The first picture represents the tree initially with the number of stones for each node written above it in green. Changes applied by the current spell are highlighted in red.

输入解题思路,AI测评打分。不知道怎么写?