제출 #128237

#제출 시각아이디문제언어결과실행 시간메모리
128237zeyad49Pipes (CEOI15_pipes)Java
10 / 100
191 ms65540 KiB
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...