結果

問題 No.95 Alice and Graph
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-08 15:21:50
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 3,080 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 77,356 KB
実行使用メモリ 292,236 KB
最終ジャッジ日時 2023-09-06 21:40:05
合計ジャッジ時間 16,205 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,507 ms
233,220 KB
testcase_01 AC 297 ms
100,264 KB
testcase_02 AC 295 ms
102,804 KB
testcase_03 AC 77 ms
78,868 KB
testcase_04 AC 2,157 ms
281,252 KB
testcase_05 AC 1,806 ms
273,328 KB
testcase_06 AC 2,081 ms
280,388 KB
testcase_07 AC 289 ms
100,256 KB
testcase_08 AC 80 ms
78,744 KB
testcase_09 AC 67 ms
76,760 KB
testcase_10 AC 70 ms
78,728 KB
testcase_11 AC 88 ms
79,912 KB
testcase_12 AC 84 ms
79,280 KB
testcase_13 AC 3,080 ms
292,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K=map(int,raw_input().split())
graph = [[50000 for i in range(N)] for j in range(N)]
for i in range(M):
    u,v=map(int,raw_input().split())
    graph[u-1][v-1]=1
    graph[v-1][u-1]=1
for i in range(N):
    for j in range(N):
        for k in range(N):
            graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k])
points=[0]
for i in range(N-1,0,-1):
    if len(points) == K+1:
        break
    points.append(i)
    size=len(points)
    totalDist=[[50000 for i in range(size)] for j in range(1<<size)]
    totalDist[1][0]=0
    for m in range(1<<size):
        for s in range(size):
            if (m&(1<<s)) >0 and totalDist[m][s]!=50000:
                for t in range(size):
                    if(m&(1<<t)) == 0:
                        totalDist[m|(1<<t)][t]=min(totalDist[m|(1<<t)][t],totalDist[m][s]+graph[points[s]][points[t]])
    ok=False
    for end in range(size):
        if totalDist[(1<<size)-1][end]<=K:
            ok=True
            break
    if ok==False:
        points.pop()
ans=0
for p in points:
    #print p
    ans+=(1<<p)-1
print ans
0