이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |