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

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

☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺ · 发布于 2023-10-05 · 浏览 612 回复 3

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;

}

全部回复 共 3 条

  1. Papyrus在审判你 #1 ·

    等着抄10遍把

  2. Papyrus在审判你 #2 ·

    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; }

  3. 11 #3 ·

    乐

发表回复