{"id":"fcc3ebe0-3710-44ce-a244-1a18da8811d7","name":"New Year Tree","description":"<a href=\"https://codeforces.com/contest/620/problem/E\">https://codeforces.com/contest/620/problem/E</a>","inputFormat":".","outputFormat":".","constraints":".","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n static InputReader in = new InputReader(System.in);\r\n static PrintWriter out = new PrintWriter(System.out);\r\n /*\r\n input_functions in.nextInt(); in.nextIntArray(n); in.nextIntArray1(n);\r\n output_functions out.println(); out.print();\r\n */\r\n\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n // write your code here.\r\n\r\n\r\n out.close();\r\n }\r\n\r\n private static class InputReader implements AutoCloseable {\r\n\r\n private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\r\n\r\n\r\n private static final InputStream DEFAULT_STREAM = System.in;\r\n\r\n private static final int MAX_DECIMAL_PRECISION = 21;\r\n\r\n private int c;\r\n\r\n private final byte[] buf;\r\n private final int bufferSize;\r\n private int bufIndex;\r\n private int numBytesRead;\r\n\r\n private final InputStream stream;\r\n\r\n private static final byte EOF = -1;\r\n\r\n private static final byte NEW_LINE = 10;\r\n\r\n private static final byte SPACE = 32;\r\n\r\n private static final byte DASH = 45;\r\n\r\n private static final byte DOT = 46;\r\n private char[] charBuffer;\r\n private static final byte[] bytes = new byte[58];\r\n private static final int[] ints = new int[58];\r\n private static final char[] chars = new char[128];\r\n\r\n static {\r\n char ch = '' '';\r\n int value = 0;\r\n byte _byte = 0;\r\n for (int i = 48; i < 58; i++)\r\n bytes[i] = _byte++;\r\n for (int i = 48; i < 58; i++)\r\n ints[i] = value++;\r\n for (int i = 32; i < 128; i++)\r\n chars[i] = ch++;\r\n }\r\n\r\n public InputReader() {\r\n this(DEFAULT_STREAM, DEFAULT_BUFFER_SIZE);\r\n }\r\n public InputReader(int bufferSize) {\r\n this(DEFAULT_STREAM, bufferSize);\r\n }\r\n public InputReader(InputStream stream) {\r\n this(stream, DEFAULT_BUFFER_SIZE);\r\n }\r\n public InputReader(InputStream stream, int bufferSize) {\r\n if (stream == null || bufferSize <= 0)\r\n throw new IllegalArgumentException();\r\n buf = new byte[bufferSize];\r\n charBuffer = new char[128];\r\n this.bufferSize = bufferSize;\r\n this.stream = stream;\r\n }\r\n private byte read() throws IOException {\r\n\r\n if (numBytesRead == EOF)\r\n throw new IOException();\r\n\r\n if (bufIndex >= numBytesRead) {\r\n bufIndex = 0;\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n }\r\n\r\n return buf[bufIndex++];\r\n }\r\n private int readJunk(int token) throws IOException {\r\n\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n do {\r\n\r\n while (bufIndex < numBytesRead) {\r\n if (buf[bufIndex] > token)\r\n return 0;\r\n bufIndex++;\r\n }\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n bufIndex = 0;\r\n\r\n } while (true);\r\n\r\n }\r\n public byte nextByte() throws IOException {\r\n return (byte) nextInt();\r\n }\r\n public int nextInt() throws IOException {\r\n\r\n if (readJunk(DASH - 1) == EOF)\r\n throw new IOException();\r\n int sgn = 1, res = 0;\r\n\r\n c = buf[bufIndex];\r\n if (c == DASH) {\r\n sgn = -1;\r\n bufIndex++;\r\n }\r\n\r\n do {\r\n\r\n while (bufIndex < numBytesRead) {\r\n if (buf[bufIndex] > SPACE) {\r\n res = (res << 3) + (res << 1);\r\n res += ints[buf[bufIndex++]];\r\n } else {\r\n bufIndex++;\r\n return res * sgn;\r\n }\r\n }\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return res * sgn;\r\n bufIndex = 0;\r\n\r\n } while (true);\r\n\r\n }\r\n public int[] nextIntArray(int n) throws IOException {\r\n int[] ar = new int[n];\r\n for (int i = 0; i < n; i++)\r\n ar[i] = nextInt();\r\n return ar;\r\n }\r\n public int[] nextIntArray1(int n) throws IOException {\r\n int[] ar = new int[n + 1];\r\n for (int i = 1; i <= n; i++)\r\n ar[i] = nextInt();\r\n return ar;\r\n }\r\n public void close() throws IOException {\r\n stream.close();\r\n }\r\n\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"7 10\r\n1 1 1 1 1 1 1\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n1 3 2\r\n2 1\r\n1 4 3\r\n2 1\r\n1 2 5\r\n2 1\r\n1 6 4\r\n2 1\r\n2 2\r\n2 3\r\n","sampleOutput":"2\r\n3\r\n4\r\n5\r\n1\r\n2\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"debe0517-0a6b-4d6b-b283-3f14ab81501d","name":"Euler Tour For Experts","slug":"euler-tour-for-experts-1013","type":0},{"id":"35afbdd7-6551-40a5-8472-9b1bbff12076","name":"New Year Tree","slug":"new-year-tree","type":1}],"next":{"id":"4a2b8b89-7e26-49dd-a357-746ca351f3f9","name":"Lca - Lowest Common Ancestor - Euler Tour","type":1,"slug":"lca-lowest-common-ancestor-euler-tour"},"prev":{"id":"9a2b2c8f-ec57-4bb4-98a4-4402c0145fa6","name":"Subtree Sum","type":1,"slug":"subtree-sum"}}}

New Year Tree

<a href="https://codeforces.com/contest/620/problem/E">https://codeforces.com/contest/620/problem/E</a>

{"id":"fcc3ebe0-3710-44ce-a244-1a18da8811d7","name":"New Year Tree","description":"<a href=\"https://codeforces.com/contest/620/problem/E\">https://codeforces.com/contest/620/problem/E</a>","inputFormat":".","outputFormat":".","constraints":".","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n static InputReader in = new InputReader(System.in);\r\n static PrintWriter out = new PrintWriter(System.out);\r\n /*\r\n input_functions in.nextInt(); in.nextIntArray(n); in.nextIntArray1(n);\r\n output_functions out.println(); out.print();\r\n */\r\n\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n // write your code here.\r\n\r\n\r\n out.close();\r\n }\r\n\r\n private static class InputReader implements AutoCloseable {\r\n\r\n private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\r\n\r\n\r\n private static final InputStream DEFAULT_STREAM = System.in;\r\n\r\n private static final int MAX_DECIMAL_PRECISION = 21;\r\n\r\n private int c;\r\n\r\n private final byte[] buf;\r\n private final int bufferSize;\r\n private int bufIndex;\r\n private int numBytesRead;\r\n\r\n private final InputStream stream;\r\n\r\n private static final byte EOF = -1;\r\n\r\n private static final byte NEW_LINE = 10;\r\n\r\n private static final byte SPACE = 32;\r\n\r\n private static final byte DASH = 45;\r\n\r\n private static final byte DOT = 46;\r\n private char[] charBuffer;\r\n private static final byte[] bytes = new byte[58];\r\n private static final int[] ints = new int[58];\r\n private static final char[] chars = new char[128];\r\n\r\n static {\r\n char ch = '' '';\r\n int value = 0;\r\n byte _byte = 0;\r\n for (int i = 48; i < 58; i++)\r\n bytes[i] = _byte++;\r\n for (int i = 48; i < 58; i++)\r\n ints[i] = value++;\r\n for (int i = 32; i < 128; i++)\r\n chars[i] = ch++;\r\n }\r\n\r\n public InputReader() {\r\n this(DEFAULT_STREAM, DEFAULT_BUFFER_SIZE);\r\n }\r\n public InputReader(int bufferSize) {\r\n this(DEFAULT_STREAM, bufferSize);\r\n }\r\n public InputReader(InputStream stream) {\r\n this(stream, DEFAULT_BUFFER_SIZE);\r\n }\r\n public InputReader(InputStream stream, int bufferSize) {\r\n if (stream == null || bufferSize <= 0)\r\n throw new IllegalArgumentException();\r\n buf = new byte[bufferSize];\r\n charBuffer = new char[128];\r\n this.bufferSize = bufferSize;\r\n this.stream = stream;\r\n }\r\n private byte read() throws IOException {\r\n\r\n if (numBytesRead == EOF)\r\n throw new IOException();\r\n\r\n if (bufIndex >= numBytesRead) {\r\n bufIndex = 0;\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n }\r\n\r\n return buf[bufIndex++];\r\n }\r\n private int readJunk(int token) throws IOException {\r\n\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n do {\r\n\r\n while (bufIndex < numBytesRead) {\r\n if (buf[bufIndex] > token)\r\n return 0;\r\n bufIndex++;\r\n }\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return EOF;\r\n bufIndex = 0;\r\n\r\n } while (true);\r\n\r\n }\r\n public byte nextByte() throws IOException {\r\n return (byte) nextInt();\r\n }\r\n public int nextInt() throws IOException {\r\n\r\n if (readJunk(DASH - 1) == EOF)\r\n throw new IOException();\r\n int sgn = 1, res = 0;\r\n\r\n c = buf[bufIndex];\r\n if (c == DASH) {\r\n sgn = -1;\r\n bufIndex++;\r\n }\r\n\r\n do {\r\n\r\n while (bufIndex < numBytesRead) {\r\n if (buf[bufIndex] > SPACE) {\r\n res = (res << 3) + (res << 1);\r\n res += ints[buf[bufIndex++]];\r\n } else {\r\n bufIndex++;\r\n return res * sgn;\r\n }\r\n }\r\n numBytesRead = stream.read(buf);\r\n if (numBytesRead == EOF)\r\n return res * sgn;\r\n bufIndex = 0;\r\n\r\n } while (true);\r\n\r\n }\r\n public int[] nextIntArray(int n) throws IOException {\r\n int[] ar = new int[n];\r\n for (int i = 0; i < n; i++)\r\n ar[i] = nextInt();\r\n return ar;\r\n }\r\n public int[] nextIntArray1(int n) throws IOException {\r\n int[] ar = new int[n + 1];\r\n for (int i = 1; i <= n; i++)\r\n ar[i] = nextInt();\r\n return ar;\r\n }\r\n public void close() throws IOException {\r\n stream.close();\r\n }\r\n\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"7 10\r\n1 1 1 1 1 1 1\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n1 3 2\r\n2 1\r\n1 4 3\r\n2 1\r\n1 2 5\r\n2 1\r\n1 6 4\r\n2 1\r\n2 2\r\n2 3\r\n","sampleOutput":"2\r\n3\r\n4\r\n5\r\n1\r\n2\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"debe0517-0a6b-4d6b-b283-3f14ab81501d","name":"Euler Tour For Experts","slug":"euler-tour-for-experts-1013","type":0},{"id":"35afbdd7-6551-40a5-8472-9b1bbff12076","name":"New Year Tree","slug":"new-year-tree","type":1}],"next":{"id":"4a2b8b89-7e26-49dd-a357-746ca351f3f9","name":"Lca - Lowest Common Ancestor - Euler Tour","type":1,"slug":"lca-lowest-common-ancestor-euler-tour"},"prev":{"id":"9a2b2c8f-ec57-4bb4-98a4-4402c0145fa6","name":"Subtree Sum","type":1,"slug":"subtree-sum"}}}
plane

Editor


Loading...

New Year Tree

hard

https://codeforces.com/contest/620/problem/E

Constraints

.

Format

Input

.

Output

.

Example

Sample Input

7 10 1 1 1 1 1 1 1 1 2 1 3 1 4 3 5 3 6 3 7 1 3 2 2 1 1 4 3 2 1 1 2 5 2 1 1 6 4 2 1 2 2 2 3

Sample Output

2 3 4 5 1 2

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode