Submission #1372161
Source Code Expand
import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.List; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] a = new int[M]; int[] b = new int[M]; sc.fill(a, b); List<List<Integer>> root = new ArrayList<>(N); for (int i = 0; i < N; i++) { root.add(new ArrayList<>()); } for (int i = 0; i < M; i++) { root.get(a[i] - 1).add(b[i] - 1); root.get(b[i] - 1).add(a[i] - 1); } Deque<List<Integer>> queue = new ArrayDeque<>(); queue.add(Arrays.asList(1)); int count = 0; while (!queue.isEmpty()) { List<Integer> list = queue.poll(); if (list.size() == N) { count++; continue; } int last = list.get(list.size() - 1); boolean added = false; for (int next : root.get(last)) { if (!list.contains(next)) { List<Integer> copy = new ArrayList<>(list); copy.add(next); queue.add(copy); added = true; } } } System.out.println(count); } private static boolean isDebug = System.getProperty("sun.desktop") != null; private static void debug(Object... o) { if (isDebug) { System.err.println(Arrays.deepToString(o)); } } public static class Scanner { private BufferedInputStream inputStream; public Scanner(InputStream in) { inputStream = new BufferedInputStream(in); } public int nextInt() throws IOException { int num = 0; int read = skip(); do { num = num * 10 + (read - 0x30); } while ((read = inputStream.read()) > 0x20); return num; } public void fill(int[] a) throws IOException { for (int i = 0; i < a.length; i++) { a[i] = nextInt(); } } public void fill(int[] a, int[] b) throws IOException { if (a.length != b.length) { throw new IllegalArgumentException(); } for (int i = 0; i < a.length; i++) { a[i] = nextInt(); b[i] = nextInt(); } } public long nextLong() throws IOException { long num = 0; int read = skip(); do { num = num * 10 + (read - 0x30); } while ((read = inputStream.read()) > 0x20); return num; } public void fill(long[] a) throws IOException { for (int i = 0; i < a.length; i++) { a[i] = nextLong(); } } public void fill(long[] a, long[] b) throws IOException { if (a.length != b.length) { throw new IllegalArgumentException(); } for (int i = 0; i < a.length; i++) { a[i] = nextLong(); b[i] = nextLong(); } } public long[] nextLong(int n) throws IOException { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } public String next() throws IOException { StringBuilder builder = new StringBuilder(); int read = skip(); do { builder.append((char) read); } while ((read = inputStream.read()) > 0x20); return builder.toString(); } private int skip() throws IOException { int read; while ((read = inputStream.read()) <= 0x20) ; return read; } } }
Submission Info
Submission Time | |
---|---|
Task | C - One-stroke Path |
User | YujiSoftware |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 3363 Byte |
Status | WA |
Exec Time | 116 ms |
Memory | 22868 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
All | sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 69 ms | 18132 KB |
sample_02.txt | AC | 69 ms | 18516 KB |
subtask_1_01.txt | AC | 70 ms | 21332 KB |
subtask_1_02.txt | AC | 73 ms | 19156 KB |
subtask_1_03.txt | AC | 73 ms | 18004 KB |
subtask_1_04.txt | AC | 114 ms | 20948 KB |
subtask_1_05.txt | AC | 69 ms | 18260 KB |
subtask_1_06.txt | WA | 68 ms | 21076 KB |
subtask_1_07.txt | WA | 69 ms | 18644 KB |
subtask_1_08.txt | WA | 70 ms | 17748 KB |
subtask_1_09.txt | WA | 71 ms | 19284 KB |
subtask_1_10.txt | AC | 77 ms | 19412 KB |
subtask_1_11.txt | WA | 77 ms | 18644 KB |
subtask_1_12.txt | WA | 89 ms | 22868 KB |
subtask_1_13.txt | WA | 116 ms | 20564 KB |