Submission #4049397


Source Code Expand

# ABC 054
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]
def zeros2(n, m): return [[0 for i in range(m)] for j in range(n)]

debug = True
def db(x): 
    if debug: print(x)

debug = False
N,m = getIntList()
org = zeros(m)

for i in range(m):    org[i] = getIntList()

db(('org graph',org))
Count = 0

def find(graph, fromNode, route): # -1: NG, >=OK、評価値
    global Count
    db(('find in',fromNode, route))
    if fromNode in route: return -1
    else:
        route = route + [fromNode]  # +=だとrouteを書き換えてしまう
        if len(route)==N: 
            db(('N',N))
            Count += 1
            return 0
        for edge in graph:
            if edge[0]==fromNode:  # graphのソート、一旦fromが見つかった後の中断
                val = find(graph, edge[1], route)
                #if val==0: 
                #    db(('found', route, edge[1]))
                #    return 0
        #db(('cannot',fromNode))
        return -1
    
graph = zeros(m*2)
for i in range(m):
    graph[i*2] = org[i]
    graph[i*2+1] = [org[i][1], org[i][0]]
graph.sort()
db(('new graph',graph))
route = []
find(graph, 1, route)
print(Count)

Submission Info

Submission Time
Task C - One-stroke Path
User shinjisu
Language Python (3.4.3)
Score 300
Code Size 1301 Byte
Status AC
Exec Time 59 ms
Memory 3064 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 18 ms 3064 KB
sample_02.txt AC 18 ms 3064 KB
subtask_1_01.txt AC 18 ms 3064 KB
subtask_1_02.txt AC 18 ms 3064 KB
subtask_1_03.txt AC 17 ms 3064 KB
subtask_1_04.txt AC 59 ms 3064 KB
subtask_1_05.txt AC 18 ms 3064 KB
subtask_1_06.txt AC 18 ms 3064 KB
subtask_1_07.txt AC 18 ms 3064 KB
subtask_1_08.txt AC 18 ms 3064 KB
subtask_1_09.txt AC 18 ms 3064 KB
subtask_1_10.txt AC 21 ms 3064 KB
subtask_1_11.txt AC 20 ms 3064 KB
subtask_1_12.txt AC 33 ms 3064 KB
subtask_1_13.txt AC 49 ms 3064 KB