#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } // graph template // ref : https://ei1333.github.io/library/graph/graph-template.cpp template struct Edge{ int from,to; T w; int idx; Edge()=default; Edge(int from,int to,T w=1,int idx=-1):from(from),to(to),w(w),idx(idx){} operator int() const{return to;} }; template vector> WarshallFloyd(vector> mat, T inf=1000000100){ int n=(int)mat.size(); for(int k=0;k>n>>m; vector> mat(n,vector(n,LINF)); rep(i,n) mat[i][i]=0; rep(i,m){ int u,v;ll w;cin>>u>>v>>w;u--,v--; chmin(mat[u][v],w); } mat=WarshallFloyd(mat,LINF); rep(i,n){ ll res=0; rep(j,n) if(mat[i][j]