1 条题解

  • 0
    @ 2022-3-6 18:12:42
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<queue>
    #include<deque>
    #include<cstdio>
    #include<algorithm>
    #include<string>
    #include<list>
    #define int long long
    #define itn int
    #pragma GCC optimize(3)
    #pragma GCC optimize(2)
    #pragma GCC target("avx")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("inline")
    #pragma GCC optimize("-fgcse")
    #pragma GCC optimize("-fgcse-lm")
    #pragma GCC optimize("-fipa-sra")
    #pragma GCC optimize("-ftree-pre")
    #pragma GCC optimize("-ftree-vrp")
    #pragma GCC optimize("-fpeephole2")
    #pragma GCC optimize("-ffast-math")
    #pragma GCC optimize("-fsched-spec")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("-falign-jumps")
    #pragma GCC optimize("-falign-loops")
    #pragma GCC optimize("-falign-labels")
    #pragma GCC optimize("-fdevirtualize")
    #pragma GCC optimize("-fcaller-saves")
    #pragma GCC optimize("-fcrossjumping")
    #pragma GCC optimize("-fthread-jumps")
    #pragma GCC optimize("-funroll-loops")
    #pragma GCC optimize("-fwhole-program")
    #pragma GCC optimize("-freorder-blocks")
    #pragma GCC optimize("-fschedule-insns")
    #pragma GCC optimize("inline-functions")
    #pragma GCC optimize("-ftree-tail-merge")
    #pragma GCC optimize("-fschedule-insns2")
    #pragma GCC optimize("-fstrict-aliasing")
    #pragma GCC optimize("-fstrict-overflow")
    #pragma GCC optimize("-falign-functions")
    #pragma GCC optimize("-fcse-skip-blocks")
    #pragma GCC optimize("-fcse-follow-jumps")
    #pragma GCC optimize("-fsched-interblock")
    #pragma GCC optimize("-fpartial-inlining")
    #pragma GCC optimize("no-stack-protector")
    #pragma GCC optimize("-freorder-functions")
    #pragma GCC optimize("-findirect-inlining")
    #pragma GCC optimize("-fhoist-adjacent-loads")
    #pragma GCC optimize("-frerun-cse-after-loop")
    #pragma GCC optimize("inline-small-functions")
    #pragma GCC optimize("-finline-small-functions")
    #pragma GCC optimize("-ftree-switch-conversion")
    #pragma GCC optimize("-foptimize-sibling-calls")
    #pragma GCC optimize("-fexpensive-optimizations")
    #pragma GCC optimize("-funsafe-loop-optimizations")
    #pragma GCC optimize("inline-functions-called-once")
    #pragma GCC optimize("-fdelete-null-pointer-checks")
    #pragma GCC optimize("Ofast", "inline", "-ffast-math")
    #pragma GCC target("avx,sse2,sse3,sse4,mmx")
    #pragma GCC optimize("-fgcse")
    #define DEBUG printf("Baylor AK IOI\n");
    #pragma GCC optimize("Ofast,unroll-loops,fast-math")
    #pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
    #pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
    using namespace std;
    int top,id,minn,sum,head[100005],to[100005],ne[100005],dis[100005],vis[100005],w[1000005],n;
    void init(int x,int y,int z){
    	to[++top]=y;
    	w[top]=z;
    	ne[top]=head[x],head[x]=top;
    	return;
    } 
    inline int prim(){
    	memset(dis,0x3f,sizeof(dis));
    	dis[1]=0;
    	sum=0;
    	for(int i=1;i<=n;i++){
    		id=-1,minn=100000;
    		for(int j=1;j<=n;j++){
    			if(!vis[j]&&dis[j]<minn){
    				minn=dis[j];
    				id=j;
    			}
    		}
    		vis[id]=1;
    		sum+=minn;
    		for(int j=head[id];j;j=ne[j]){
    			if(!vis[to[j]]&&w[j]<dis[to[j]]){
    				dis[to[j]]=w[j];
    			}
    		}
    	}
    	return sum;
    }
    signed main(){
    	scanf("%lld",&n);
    	for(int k=1;k<=n;k++){
    		for(int i=1;i<=n;i++){
    			int x;
    			cin>>x;
    			if(x==0)continue;
    			else{
    				init(k,i,x);
    				init(i,k,x);			
    			}
    		}
    	}
    	int s=prim();
    	cout<<s;
    	return 0;
    }
    //register
    //unsigned
    //system("pause");
    //system("cls");
    //system("color OA");   0b  fc 75
    
    • 1

    信息

    ID
    584
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    28
    已通过
    17
    上传者