Submission #1371569


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

	static int n, m;
	static ArrayList<ArrayList<Integer>> al;
	static int count;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		al = new ArrayList<>();
		for (int i = 0; i < n; i++)
			al.add(new ArrayList<>());
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			al.get(a).add(b);
			al.get(b).add(a);
		}

		count = 0;
		boolean[] reach = new boolean[n];
		dfs(0, 0, reach);
		out.println(count);
		out.flush();
	}

	static void dfs(int now, int num, boolean[] reach) {
		if (num == n - 1) {
			count++;
			return;
		}
		for (Integer v : al.get(now)) {
			reach[now] = true;
			if (!reach[v]) dfs(v, num + 1, reach);
			reach[now] = false;
		}
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) { return false; }
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long nextLong() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

}

Submission Info

Submission Time
Task C - One-stroke Path
User deka0106
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 3192 Byte
Status AC
Exec Time 91 ms
Memory 21716 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 15
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 72 ms 20564 KB
sample_02.txt AC 70 ms 21332 KB
subtask_1_01.txt AC 71 ms 19796 KB
subtask_1_02.txt AC 71 ms 20052 KB
subtask_1_03.txt AC 72 ms 20052 KB
subtask_1_04.txt AC 78 ms 21076 KB
subtask_1_05.txt AC 71 ms 21204 KB
subtask_1_06.txt AC 71 ms 21204 KB
subtask_1_07.txt AC 75 ms 20436 KB
subtask_1_08.txt AC 71 ms 21332 KB
subtask_1_09.txt AC 72 ms 19284 KB
subtask_1_10.txt AC 74 ms 21332 KB
subtask_1_11.txt AC 85 ms 21204 KB
subtask_1_12.txt AC 88 ms 21588 KB
subtask_1_13.txt AC 91 ms 21716 KB