Submission #128237

# Submission time Handle Problem Language Result Execution time Memory
128237 2019-07-10T14:56:37 Z zeyad49 Pipes (CEOI15_pipes) Java 11
10 / 100
191 ms 65540 KB
import java.io.*;
import java.util.*;

public class pipes {

	static boolean[] visited;

	static PrintWriter out = new PrintWriter(System.out);
	static int[][] cnt;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		cnt = new int[n][n];
		int m = sc.nextInt();
		while (m-- > 0) {
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
			cnt[u][v]++;
			cnt[v][u]++;
		}
		visited = new boolean[n];
		for (int u = 0; u < n; u++)
			for (int v = u + 1; v < n; v++) {
				if (cnt[u][v] != 1)
					continue;
				cnt[u][v] = cnt[v][u] = 0;
				Arrays.fill(visited, false);
				dfs(u);
				if (!visited[v])
					out.printf("%d %d\n", u + 1, v + 1);

				cnt[u][v] = cnt[v][u] = 1;
			}

		out.close();

	}

	static void dfs(int u) {
		visited[u] = true;
		for (int v = 0; v < visited.length; v++)
			if (cnt[u][v] > 0 && !visited[v])
				dfs(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();
		}

	}

}
# Verdict Execution time Memory Grader output
1 Correct 121 ms 10532 KB Output is correct
2 Correct 118 ms 10492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 167 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 185 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 191 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 159 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 165 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 159 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 178 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 169 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 168 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -