Submission #1696394
Source Code Expand
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.Scanner; import java.util.Stack; class Main { public static void main(String[] args) { new Main().compute(); } void compute() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); List<Integer>[] adjacents = new List[N]; for (int i = 0; i < N; i++) { adjacents[i] = new ArrayList<>(); } for (int i = 0; i < N - 1; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; adjacents[a].add(b); adjacents[b].add(a); } int[] fromFennec = new int[N]; Arrays.fill(fromFennec, N); Stack<Integer> stk = new Stack<>(); fromFennec[0] = 0; stk.push(0); while (!stk.empty()) { int start = stk.pop(); int dist = fromFennec[start] + 1; for (int i = 0; i < N; i++) { if (adjacents[start].contains(new Integer(i)) && fromFennec[i] == N) { fromFennec[i] = dist; stk.push(i); } } } int[] fromSnuke = new int[N]; Arrays.fill(fromSnuke, N); fromSnuke[N - 1] = 0; stk.push(N - 1); while (!stk.empty()) { int start = stk.pop(); int dist = fromSnuke[start] + 1; for (int i = 0; i < N; i++) { if (adjacents[start].contains(new Integer(i)) && fromSnuke[i] == N) { fromSnuke[i] = dist; stk.push(i); } } } int sum = 0; for (int i = 0; i < N; i++) { if (fromFennec[i] > fromSnuke[i]) { sum++; } } if (sum >= N / 2) { System.out.println("Snuke"); } else { System.out.println("Fennec"); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Fennec VS. Snuke |
User | packer_jp |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2137 Byte |
Status | WA |
Exec Time | 2109 ms |
Memory | 102660 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 / 400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt |
All | 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 100 ms | 19028 KB |
00_example_02.txt | AC | 99 ms | 19796 KB |
01.txt | AC | 101 ms | 18900 KB |
02.txt | AC | 101 ms | 21588 KB |
03.txt | WA | 97 ms | 18644 KB |
04.txt | WA | 100 ms | 19668 KB |
05.txt | TLE | 2106 ms | 82992 KB |
06.txt | TLE | 2109 ms | 91408 KB |
07.txt | TLE | 2109 ms | 81132 KB |
08.txt | TLE | 2109 ms | 93528 KB |
09.txt | AC | 98 ms | 21332 KB |
10.txt | TLE | 2109 ms | 79536 KB |
11.txt | TLE | 2109 ms | 102372 KB |
12.txt | TLE | 2109 ms | 102620 KB |
13.txt | TLE | 2106 ms | 102660 KB |
14.txt | TLE | 2109 ms | 88100 KB |
15.txt | TLE | 2109 ms | 87824 KB |
16.txt | TLE | 2109 ms | 102088 KB |
17.txt | TLE | 2105 ms | 101908 KB |
18.txt | TLE | 2106 ms | 100332 KB |
19.txt | TLE | 2109 ms | 102108 KB |