QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572976 | #9310. Permutation Counting 4 | daring | RE | 0ms | 0kb | Java11 | 1.2kb | 2024-09-18 16:58:30 | 2024-09-18 16:58:31 |
answer
import java.util.*;
public class Main {
static long sum = 0;
static List<List<Long>> a;
static boolean[] vis;
public static void solve() {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
sum = 0;
a = new ArrayList<>(n + 1);
vis = new boolean[n + 1];
for (int i = 0; i <= n; i++) {
a.add(new ArrayList<>());
}
for (int i = 1; i <= n; i++) {
long u = scanner.nextLong();
long v = scanner.nextLong();
u--;
a.get((int) u).add(v);
a.get((int) v).add(u);
}
dfs(0);
System.out.println(sum == n + 1 ? 1 : 0);
}
public static void dfs(int u) {
if (!vis[u]) {
sum++;
vis[u] = true;
for (long p : a.get(u)) {
if (!vis[(int) p]) {
dfs((int) p);
}
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
solve();
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2