Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int counter = 0;
- int[] array = new int[n + 1];
- for (int i = 0; i < n - 1; i++) {
- int x1 = sc.nextInt();
- int x2 = sc.nextInt();
- array[x2] = x1;
- }
- for (int a = 1; a <= n; a++) {
- for (int b = 1; b <= n; b++) {
- if (a == b) continue;
- for (int c = 1; c <= n; c++) {
- if (c == a || c == b) continue;
- for (int d = 1; d <= n; d++) {
- if (d == a || d == b || d == c) continue;
- for (int e = 1; e <= n; e++) {
- if (e == a || e == b || e == c || e == d) continue;
- for (int f = 1; f <= n; f++) {
- if (f == a || f == b || f == c || f == d || f == e) continue;
- for (int g = 1; g <= n; g++) {
- if (g == a || g == b || g == c || g == d || g == e || g == f) continue;
- if ((array[b] == a || array[a] == b) && (array[c] == b || array[b] == c) && (array[d] == b || array[b] == d) && (array[e] == b || array[b] == e) && (array[f] == d || array[d] == f) && (array[g] == d || array[d] == g)){
- counter++;
- }
- }
- }
- }
- }
- }
- }
- }
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement