結果

問題 No.95 Alice and Graph
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-08 15:32:01
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 2,912 ms / 5,000 ms
コード長 1,080 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 77,856 KB
実行使用メモリ 297,568 KB
最終ジャッジ日時 2023-09-06 21:40:40
合計ジャッジ時間 12,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,345 ms
229,488 KB
testcase_01 AC 278 ms
103,496 KB
testcase_02 AC 277 ms
102,648 KB
testcase_03 AC 79 ms
78,836 KB
testcase_04 AC 1,735 ms
291,204 KB
testcase_05 AC 1,344 ms
269,516 KB
testcase_06 AC 1,433 ms
294,688 KB
testcase_07 AC 281 ms
103,232 KB
testcase_08 AC 80 ms
78,884 KB
testcase_09 AC 67 ms
76,160 KB
testcase_10 AC 69 ms
78,860 KB
testcase_11 AC 91 ms
79,728 KB
testcase_12 AC 89 ms
79,520 KB
testcase_13 AC 2,912 ms
297,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K=map(int,raw_input().split())
graph = [[50000 for i in xrange(N)] for j in xrange(N)]
for i in xrange(M):
    u,v=map(int,raw_input().split())
    graph[u-1][v-1]=1
    graph[v-1][u-1]=1
for i in xrange(N):
    for j in xrange(N):
        for k in xrange(N):
            graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k])
points=[0]
for i in xrange(N-1,0,-1):
    if len(points) == K+1:
        break
    points.append(i)
    size=len(points)
    totalDist=[[50000 for i in xrange(size)] for j in xrange(1<<size)]
    totalDist[1][0]=0
    for m in xrange(1<<size):
        for s in xrange(size):
            if (m&(1<<s)) >0 and totalDist[m][s]<=K:
                for t in xrange(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 xrange(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