Do you mean a solution with no python for loops? I think any solution will have some underlying for loops, so hopefully native loops are fast enough here 
import torch
import pdb

x_ = torch.randn(10,1)
key_dist_s = torch.cdist(x_, x_, p=2)

idx = torch.topk(key_dist_s, k=3, largest=True)
idx_indices =  idx.indices
a = idx_indices[:,0:2]
b = idx_indices[:,[0,2]]
print(a)
print(b)
temp = torch.cat((a, b), dim=1)
total_len = temp.size(0)*2
out = temp.reshape(total_len, -1)
print(out)

tensor([[3, 4],
        [5, 3],
        [5, 6],
        [5, 6],
        [5, 6],
        [3, 4],
        [3, 4],
        [5, 3],
        [3, 5],
        [5, 3]])
tensor([[3, 2],
        [5, 4],
        [5, 0],
        [5, 0],
        [5, 0],
        [3, 2],
        [3, 2],
        [5, 4],
        [3, 4],
        [5, 4]])
tensor([[3, 4],
        [3, 2],
        [5, 3],
        [5, 4],
        [5, 6],
        [5, 0],
        [5, 6],
        [5, 0],
        [5, 6],
        [5, 0],
        [3, 4],
        [3, 2],
        [3, 4],
        [3, 2],
        [5, 3],
        [5, 4],
        [3, 5],
        [3, 4],
        [5, 3],
        [5, 4]])