58分,6个点RE,求调

P3366 【模板】最小生成树

Lastheart @ 2024-02-01 09:55:25

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 110;
const int INF = 0x7fffffff;
int w[N][N],Min[N];
ll MST,n,m;

bool vis[N];

void prim(){
    memset(Min,0x7f,sizeof(Min));
    memset(vis,true,sizeof(vis));
    Min[1] = 0;
    for (int i = 1;i <= n;i++){
        int k = 0;
        for (int j = 1  ;j <= N;j++)
            if (vis[j] && Min[j] < Min[k]) k = j;

        vis[k] = false;
        MST += Min[k];
        for (int j = 1; j <= n ;j++)
            if (vis[j] && w[k][j] < Min[j])
                Min[j] = w[k][j];
    }
}

int main(){
    scanf("%d%d",&n,&m);
    //memset(w,0x7f,sizeof(w));
    for (int i = 0;i <= n;i++)
        for (int j = 0;j <= n;j++)
            w[i][j] = INF;
    for (int i = 1;i <= m;i++){
        int u,v,c;
        scanf("%d%d%d",&u,&v,&c);
        w[u][v] = w[v][u] = min(c,w[u][v]);
    }
    prim();
    for (int i = 1 ;i <= n;i++)
        if (vis[i] == 1) {printf("orz\n"); return 0;}
    printf("%d",MST);
    return 0;
}

by Brilliant11001 @ 2024-02-01 09:58:14

数组开小了哥


by Brilliant11001 @ 2024-02-01 09:58:49

@Lastheart


by Lastheart @ 2024-02-01 09:59:28

@Brilliant11001 开多大


by GreenMelon @ 2024-02-01 09:59:55

1e4?


by GreenMelon @ 2024-02-01 10:00:09

@Lastheart


by Brilliant11001 @ 2024-02-01 10:01:18

@Lastheart N 开到 5010 就行了


by GreenMelon @ 2024-02-01 10:01:57

0x7ffffff改成0x7f?,你MLE了

看私信(先别把我拉黑了


|