-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteNavigation.java
More file actions
46 lines (37 loc) · 1.1 KB
/
Copy pathRouteNavigation.java
File metadata and controls
46 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class RouteNavigation {
public static int result = 0;
public static int[][] array;
public void solution(int start, int n, int[] check) {
for (int i = 1; i <= n; i++) {
if (start == n) {
result++;
return;
}
if (array[start][i] == 0) {
continue;
}
if (check[i] == 0) {
int[] clone = check.clone();
clone[i] = 1;
solution(i, n, clone);
}
}
}
public static void main(String[] args) {
RouteNavigation t = new RouteNavigation();
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
array = new int[n + 1][n + 1];
int[] check = new int[n + 1];
for (int i = 0; i < m; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
array[x][y] = 1;
}
check[1] = 1;
t.solution(1, n, check);
System.out.println(result);
}
}