結果
| 問題 |
No.95 Alice and Graph
|
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-03-08 15:32:01 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 3,343 ms / 5,000 ms |
| コード長 | 1,080 bytes |
| コンパイル時間 | 1,857 ms |
| コンパイル使用メモリ | 76,544 KB |
| 実行使用メモリ | 296,176 KB |
| 最終ジャッジ日時 | 2024-06-24 15:58:06 |
| 合計ジャッジ時間 | 14,200 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
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
yaoshimax