QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572976#9310. Permutation Counting 4daringRE 0ms0kbJava111.2kb2024-09-18 16:58:302024-09-18 16:58:31

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 16:58:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 16:58:30]
  • 提交

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();
        }
    }
}

詳細信息

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

output:


result: