import sys readline=sys.stdin.readline read=sys.stdin.read x,y=map(int,readline().split()) N=int(readline()) X,Y,W=zip(*[list(map(float,readline().split())) for i in range(N)]) inf=1<<30 dp=[[inf]*N for bit in range(1<