Problem 1001 12343444

wmyqwqqwq | 2021-07-28 14:20:01Author
#include<stdio.h> int n,m; int ship[3001][3001]={0},count[3001]={0}; int i,j,a,b,c; int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=m;i++){ scanf("%d%d%d",&a,&b,&c); ship[a][b]=c; ship[b][a]=c; } int min_ship=0; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(ship[i][j]!=0){ count[i]+=ship[i][j]; } if(j==n&&count[i]<min_ship){ min_ship=count[i]; } } if(i==1){ min_ship=count[1]; } } printf("%d",min_ship); } return 0; }