제출 #22722

#제출 시각아이디문제언어결과실행 시간메모리
22722dhsrhkdgus (#40)Logistical Metropolis (KRIII5_LM)C++14
2 / 7
183 ms2204 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))

#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321
#define insert push_back
int N,M,T,K,H;
vector<Pi> E[1050]; vector<pair<int,Pi>> Elist;
int pa[1050];  
int find(int x){
	if( pa[x] == x )return x;
	return pa[x] = find(pa[x]);
}

void uni(int a, int b){
	a = find(a); b = find(b);
	pa[a] = b;
}
void solve(int n){
	rep(i,1050) pa[i] = i;
	int ans = 0;
	for(auto e : E[n]){
		uni(e.Fi, n);
		ans += e.Se;
	}

	sort(all(Elist));
	for(auto e : Elist){
		int x = e.Se.Fi; int y = e.Se.Se;
		if( find(x) != find(y) ){
			ans += e.Fi;
			uni(x,y);
		}
	}
	printf("%d\n",ans);
}
int main(){
	geti(N,M);
	repp(i,M){
		int a,b,c; geti(a,b,c);
		E[a].push_back({b,c});
		E[b].push_back({a,c});
		Elist.push_back({c,{a,b}});
	}

	repp(i,N){
		solve(i);
	}

}

컴파일 시 표준 에러 (stderr) 메시지

LM.cpp: In function 'int main()':
LM.cpp:81:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  geti(N,M);
           ^
LM.cpp:83:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a,b,c; geti(a,b,c);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...