Submission #32782185
Source Code Expand
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
EReversi solver = new EReversi();
solver.solve(1, in, out);
out.close();
}
static class EReversi {
List<Integer>[] graph;
int[] subtree;
boolean[] white;
int[] parent;
void dfs(int u, int p) {
parent[u] = p;
subtree[u] = white[u] ? 1 : 0;
for (int v : graph[u]) {
if (v != p) {
dfs(v, u);
subtree[u] ^= subtree[v];
}
}
}
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
graph = Utils.listArray(n);
for (int i = 0; i < n - 1; i++) {
int from = in.nextInt() - 1, to = in.nextInt() - 1;
graph[from].add(to);
graph[to].add(from);
}
white = new boolean[n];
String colors = in.next();
for (int i = 0; i < n; i++) {
white[i] = colors.charAt(i) == 'W';
}
subtree = new int[n];
parent = new int[n];
dfs(0, -1);
if (subtree[0] == 0) {
out.println("-1");
return;
}
boolean[] used = new boolean[n];
TreeSet<Integer> canUse = new TreeSet<>();
for (int i = 0; i < n; i++) {
if (white[i] && subtree[i] == 1) {
canUse.add(i);
}
}
for (int IT = 0; IT < n; IT++) {
int vertex = canUse.pollFirst();
used[vertex] = true;
out.print((vertex + 1) + " ");
for (int neighbor : graph[vertex]) {
if (!used[neighbor]) {
if (white[neighbor] && subtree[neighbor] == 1) {
canUse.remove(neighbor);
}
white[neighbor] ^= true;
if (neighbor != parent[vertex]) {
subtree[neighbor] ^= 1;
}
if (white[neighbor] && subtree[neighbor] == 1) {
canUse.add(neighbor);
}
}
}
}
out.println();
}
}
static class Utils {
public static <T> List<T>[] listArray(int size) {
List<T>[] result = new List[size];
for (int i = 0; i < size; i++) {
result[i] = new ArrayList<>();
}
return result;
}
}
static class FastScanner {
public BufferedReader br;
public StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public FastScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
while (st == null || !st.hasMoreElements()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new UnknownError();
}
if (line == null) {
throw new UnknownError();
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Reversi |
| User | VArtem |
| Language | Java (OpenJDK 11.0.6) |
| Score | 0 |
| Code Size | 4625 Byte |
| Status | RE |
| Exec Time | 1065 ms |
| Memory | 100408 KiB |
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 / 700 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample01.txt, sample02.txt |
| All | in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, sample01.txt, sample02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 509 ms | 79600 KiB |
| in02.txt | AC | 494 ms | 79024 KiB |
| in03.txt | AC | 495 ms | 79808 KiB |
| in04.txt | AC | 498 ms | 79400 KiB |
| in05.txt | AC | 518 ms | 80728 KiB |
| in06.txt | AC | 496 ms | 79388 KiB |
| in07.txt | AC | 490 ms | 79000 KiB |
| in08.txt | AC | 385 ms | 81120 KiB |
| in09.txt | AC | 407 ms | 82216 KiB |
| in10.txt | RE | 921 ms | 88900 KiB |
| in11.txt | RE | 879 ms | 87348 KiB |
| in12.txt | RE | 1005 ms | 88200 KiB |
| in13.txt | RE | 878 ms | 88444 KiB |
| in14.txt | RE | 889 ms | 87140 KiB |
| in15.txt | RE | 914 ms | 87724 KiB |
| in16.txt | RE | 921 ms | 86360 KiB |
| in17.txt | RE | 897 ms | 88016 KiB |
| in18.txt | RE | 879 ms | 87856 KiB |
| in19.txt | RE | 897 ms | 87272 KiB |
| in20.txt | RE | 889 ms | 88208 KiB |
| in21.txt | RE | 894 ms | 87780 KiB |
| in22.txt | RE | 857 ms | 87620 KiB |
| in23.txt | RE | 800 ms | 84304 KiB |
| in24.txt | RE | 919 ms | 88148 KiB |
| in25.txt | RE | 1047 ms | 93956 KiB |
| in26.txt | RE | 892 ms | 95500 KiB |
| in27.txt | RE | 794 ms | 89896 KiB |
| in28.txt | RE | 997 ms | 95892 KiB |
| in29.txt | RE | 981 ms | 92560 KiB |
| in30.txt | RE | 889 ms | 93968 KiB |
| in31.txt | RE | 925 ms | 95360 KiB |
| in32.txt | RE | 1056 ms | 98588 KiB |
| in33.txt | RE | 1065 ms | 95392 KiB |
| in34.txt | RE | 916 ms | 93796 KiB |
| in35.txt | RE | 929 ms | 100408 KiB |
| in36.txt | RE | 744 ms | 90100 KiB |
| sample01.txt | AC | 111 ms | 36580 KiB |
| sample02.txt | AC | 67 ms | 32332 KiB |