Submission #128229

# Submission time Handle Problem Language Result Execution time Memory
128229 2019-07-10T14:44:54 Z zeyad49 Pipes (CEOI15_pipes) Java 11
0 / 100
834 ms 65540 KB
import java.io.*;
import java.util.*;

public class pipes {

	static ArrayList<Integer>[] adjList;
	static int[] dfs_low, dfs_num, parent;
	static int V, counter;
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		V = sc.nextInt();
		adjList = new ArrayList[V];
		for (int i = 0; i < V; i++)
			adjList[i] = new ArrayList();
		int m = sc.nextInt();
		while (m-- > 0) {
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
			adjList[u].add(v);
			adjList[v].add(u);
		}
		dfs_low = new int[V];
		dfs_num = new int[V];
		parent = new int[V];
		findArtPointsAndBridges();
		out.close();

	}

	static void findArtPointsAndBridges() // O(V + E)
	{
		for (int i = 0; i < V; ++i)
			if (dfs_num[i] == 0) {

				dfs(i);

			}
	}

	static void dfs(int u) {
		dfs_num[u] = dfs_low[u] = ++counter;
		for (int v : adjList[u])
			if (dfs_num[v] == 0) {
				parent[v] = u;

				dfs(v);

				if (dfs_low[v] > dfs_num[u])
					out.printf("%d %d%n", u + 1, v + 1);
				dfs_low[u] = Math.min(dfs_low[v], dfs_low[u]);
			} else if (parent[u] != v)
				dfs_low[u] = Math.min(dfs_low[u], dfs_num[v]);
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Compilation message

Note: pipes.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10404 KB Output is correct
2 Incorrect 123 ms 10168 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Runtime error 293 ms 18836 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 728 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 760 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 770 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 708 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 780 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 811 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 824 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 834 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -