??不理解为什么没有输出

☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺  •  8个月前


include <bits/stdc++.h>

using namespace std; int n, m, s = 0, a[10000][10000], d[10000];

void f() {

int p;
for (int i = 1; i <= n; i++) {
	for (int j = 1; j <= n; j++) {
		p = 0;
		if (a[i][j] != 0 && d[j] == 0) {
			if (a[i][j + 1] != 0) {
				int t;
				p++;
				if (a[i][j + 1] > a[i][j]) {
					t = a[i][j + 1];
					s += t;
				} else {
					t = a[i][j];
					s += t;
				}
				d[j + 1] = 1;
			} else {
				s += a[i][j];
			}
			d[j] = 1;
		}
	}
}

}

int main() {

cin >> n >> m;
memset(a, 0, sizeof(a));
memset(d, 0, m);
for (int i = 1; i <= m; i++) {
	int x, y, z;
	cin >> x >> y >> z;
	a[x][y] = z;
}
f();
cout << s;
return 0;

}


评论:

等着抄10遍把


Papyrus在审判你  •  8个月前

include<bits/stdc++.h>

using namespace std; int a[110][110]; const int big=10000111; int main() {

int n,m,x,y,z;
cin>>n>>m;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        a[i][j]=big;
    }
}
for(int i=0;i<m;i++){      
    cin>>x>>y>>z;
    a[x][y]=z;
    a[y][x]=z;

} for(int k=1;k<=n;k++){

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[i][k]+a[k][j]<a[i][j]){                 
                    a[i][j]=a[i][k]+a[k][j];
            }
        }
    }

} int s=0; for(int i=2;i<=n;i++){

   s=max(s,a[1][i]);
   if(a[1][i]==big){
       cout<<"-1";
       return 0;
   }

} cout<<s; return 0; }


Papyrus在审判你  •  8个月前

请先登录,才能进行评论