Submission #32780461
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.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);
DBridges solver = new DBridges();
solver.solve(1, in, out);
out.close();
}
static class DBridges {
List<Edge>[] graph;
int[] color;
boolean[] ans;
void dfs(int u, Edge parEdge) {
color[u] = 1;
for (int t = 0; t < graph[u].size(); t++) {
Edge e = graph[u].get(t);
if (e == parEdge) {
continue;
}
int v = e.from + e.to - u;
if (color[v] == 0) {
ans[e.id] = e.from == u;
dfs(v, e);
} else if (color[v] == 1) {
ans[e.id] = e.from == u;
}
}
color[u] = 2;
}
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt();
int[] a = in.nextIntArray(m), b = in.nextIntArray(m);
graph = Utils.listArray(n);
for (int i = 0; i < m; i++) {
a[i]--;
b[i]--;
Edge e = new Edge(a[i], b[i], i);
graph[a[i]].add(e);
graph[b[i]].add(e);
}
color = new int[n];
ans = new boolean[m];
for (int i = 0; i < n; i++) {
if (color[i] == 0) {
dfs(i, null);
}
}
for (boolean bit : ans) {
out.print(bit ? 0 : 1);
}
out.println();
}
class Edge {
int from;
int to;
int id;
public Edge(int from, int to, int id) {
this.from = from;
this.to = to;
this.id = id;
}
}
}
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();
}
public int[] nextIntArray(int n) {
int[] ret = new int[n];
for (int i = 0; i < n; i++) {
ret[i] = nextInt();
}
return ret;
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Bridges |
| User | VArtem |
| Language | Java (OpenJDK 11.0.6) |
| Score | 700 |
| Code Size | 4258 Byte |
| Status | AC |
| Exec Time | 706 ms |
| Memory | 97260 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 | 700 / 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, sample01.txt, sample02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 120 ms | 34020 KiB |
| in02.txt | AC | 105 ms | 33880 KiB |
| in03.txt | AC | 105 ms | 34108 KiB |
| in04.txt | AC | 110 ms | 34068 KiB |
| in05.txt | AC | 109 ms | 35412 KiB |
| in06.txt | AC | 670 ms | 76704 KiB |
| in07.txt | AC | 706 ms | 76600 KiB |
| in08.txt | AC | 616 ms | 78696 KiB |
| in09.txt | AC | 590 ms | 76172 KiB |
| in10.txt | AC | 662 ms | 75992 KiB |
| in11.txt | AC | 582 ms | 81500 KiB |
| in12.txt | AC | 682 ms | 81524 KiB |
| in13.txt | AC | 615 ms | 79352 KiB |
| in14.txt | AC | 696 ms | 76556 KiB |
| in15.txt | AC | 623 ms | 77204 KiB |
| in16.txt | AC | 461 ms | 70580 KiB |
| in17.txt | AC | 485 ms | 71260 KiB |
| in18.txt | AC | 454 ms | 71248 KiB |
| in19.txt | AC | 445 ms | 71144 KiB |
| in20.txt | AC | 482 ms | 71016 KiB |
| in21.txt | AC | 626 ms | 76560 KiB |
| in22.txt | AC | 571 ms | 77020 KiB |
| in23.txt | AC | 586 ms | 76724 KiB |
| in24.txt | AC | 583 ms | 76964 KiB |
| in25.txt | AC | 590 ms | 75920 KiB |
| in26.txt | AC | 85 ms | 33760 KiB |
| in27.txt | AC | 104 ms | 33736 KiB |
| in28.txt | AC | 94 ms | 33476 KiB |
| in29.txt | AC | 93 ms | 33500 KiB |
| in30.txt | AC | 109 ms | 33820 KiB |
| in31.txt | AC | 504 ms | 80540 KiB |
| in32.txt | AC | 451 ms | 97260 KiB |
| in33.txt | AC | 400 ms | 71668 KiB |
| sample01.txt | AC | 79 ms | 32516 KiB |
| sample02.txt | AC | 79 ms | 32776 KiB |