Submission #3459330
Source Code Expand
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import deque n,m = li() graph = [[] for _ in range(n)] for _ in range(m): a,b = li_() graph[a].append(b) graph[b].append(a) path = deque([a,b]) path_set = set(path) ed = b satisfied = False while not satisfied: satisfied = True for nex in graph[ed]: if nex in path_set: continue else: path_set.add(nex) path.append(nex) ed = nex satisfied = False break ed = a satisfied = False while not satisfied: satisfied = True for nex in graph[ed]: if nex in path_set: continue else: path_set.add(nex) path.appendleft(nex) ed = nex satisfied = False break path = [pi+1 for pi in path] print(len(path)) print(*path)
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | polarbear08 |
Language | Python (3.4.3) |
Score | 500 |
Code Size | 1371 Byte |
Status | AC |
Exec Time | 485 ms |
Memory | 33100 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.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 | 20 ms | 3316 KB |
sample_02.txt | AC | 20 ms | 3316 KB |
sample_03.txt | AC | 20 ms | 3316 KB |
subtask_1_01.txt | AC | 273 ms | 17112 KB |
subtask_1_02.txt | AC | 90 ms | 6644 KB |
subtask_1_03.txt | AC | 242 ms | 16972 KB |
subtask_1_04.txt | AC | 294 ms | 16476 KB |
subtask_1_05.txt | AC | 294 ms | 16476 KB |
subtask_1_06.txt | AC | 291 ms | 16988 KB |
subtask_1_07.txt | AC | 324 ms | 21724 KB |
subtask_1_08.txt | AC | 336 ms | 21596 KB |
subtask_1_09.txt | AC | 485 ms | 33100 KB |
subtask_1_10.txt | AC | 125 ms | 4852 KB |
subtask_1_11.txt | AC | 153 ms | 5492 KB |
subtask_1_12.txt | AC | 20 ms | 3316 KB |
subtask_1_13.txt | AC | 21 ms | 3316 KB |