Submission #3222841
Source Code Expand
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.List; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakharjain */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); agc014d solver = new agc014d(); solver.solve(1, in, out); out.close(); } static class agc014d { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); List[] g = new List[n]; for (int i = 0; i < n; i++) { g[i] = new ArrayList(); } for (int i = 0; i < n - 1; i++) { int a = in.nextInt(); int b = in.nextInt(); a--; b--; g[a].add(b); g[b].add(a); } for (int i = 0; i < n; i++) { int l = 0; for (int j = 0; j < g[i].size(); j++) { int v = (int) g[i].get(j); if (g[v].size() == 1) { l++; } } if (l > 1) { out.println("First"); return; } } if (n % 2 == 1) { out.println("First"); } else { out.println("Second"); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Black and White Tree |
User | leashptntl |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 4788 Byte |
Status | WA |
Exec Time | 153 ms |
Memory | 36452 KB |
Compile Error
Note: ./Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 900 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 126 ms | 34408 KB |
in10.txt | AC | 132 ms | 33348 KB |
in11.txt | AC | 150 ms | 34404 KB |
in12.txt | AC | 97 ms | 19412 KB |
in13.txt | AC | 136 ms | 32780 KB |
in14.txt | AC | 150 ms | 34404 KB |
in15.txt | AC | 139 ms | 33928 KB |
in16.txt | AC | 151 ms | 33548 KB |
in17.txt | AC | 150 ms | 35564 KB |
in18.txt | AC | 149 ms | 33108 KB |
in19.txt | AC | 153 ms | 32340 KB |
in2.txt | AC | 132 ms | 33136 KB |
in20.txt | AC | 151 ms | 32860 KB |
in21.txt | AC | 132 ms | 31348 KB |
in22.txt | AC | 131 ms | 34168 KB |
in23.txt | AC | 131 ms | 33772 KB |
in24.txt | AC | 143 ms | 33544 KB |
in25.txt | AC | 133 ms | 33536 KB |
in26.txt | WA | 152 ms | 31608 KB |
in27.txt | AC | 132 ms | 30344 KB |
in28.txt | AC | 71 ms | 20948 KB |
in29.txt | AC | 138 ms | 34552 KB |
in3.txt | AC | 134 ms | 36452 KB |
in30.txt | AC | 151 ms | 32632 KB |
in31.txt | WA | 148 ms | 33272 KB |
in32.txt | WA | 150 ms | 33888 KB |
in33.txt | WA | 141 ms | 32480 KB |
in4.txt | AC | 133 ms | 32340 KB |
in5.txt | AC | 130 ms | 31608 KB |
in6.txt | AC | 130 ms | 32020 KB |
in7.txt | AC | 132 ms | 32096 KB |
in8.txt | AC | 132 ms | 34548 KB |
in9.txt | AC | 134 ms | 35680 KB |
sample1.txt | AC | 70 ms | 20436 KB |
sample2.txt | AC | 70 ms | 21460 KB |
sample3.txt | AC | 68 ms | 18004 KB |