def g;gets.split.map(&:to_i)end n,m=g $s=(1..n).map{[0]*n} m.times{ a,b,c=g $s[a][b]=c } def dfs(done,left) left.map{|i|done.inject(0){|t,j|t+$s[j][i]}+dfs(done+[i],left-[i])}.max||0 end p dfs([],[*0...n])