답안 #71587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71587 2018-08-25T07:54:23 Z 김세빈(#2219) Logistical Metropolis (KRIII5_LM) C++11
2 / 7
110 ms 2252 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

struct edge{
	ll u, v, c;
	edge() {}
	edge(ll u, ll v, ll c) : u(u), v(v), c(c) {}
};

vector <pll> V[1010];
vector <edge> E;
ll P[1010];
ll n, m, ans;

ll find(ll p) { return p == P[p]? p : P[p] = find(P[p]); }
void unite(ll p, ll q) { P[find(p)] = find(q); }

int main()
{
	ll i, j, a, b, c;
	
	scanf("%lld%lld", &n, &m);
	
	if(n > 1000) return 0;
	
	for(i=1; i<=m; i++){
		scanf("%lld%lld%lld", &a, &b, &c);
		V[a].emplace_back(b, c);
		V[b].emplace_back(a, c);
		E.emplace_back(a, b, c);
	}
	
	sort(E.begin(), E.end(), [&](edge &ea, edge &eb){
		return ea.c < eb.c;
	});
	
	for(i=1; i<=n; i++){
		for(j=1; j<=n; j++) P[j] = j;
		ans = 0;
		
		for(pll &p: V[i]){
			ans += p.second;
			unite(i, p.first);
		}
		
		for(edge &e: E){
			if(find(e.u) != find(e.v)){
				ans += e.c;
				unite(e.u, e.v);
			}
		}
		
		printf("%lld\n", ans);
	}
	
	return 0;
}

Compilation message

LM.cpp: In function 'int main()':
LM.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
LM.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 632 KB Output is correct
2 Correct 110 ms 920 KB Output is correct
3 Correct 107 ms 920 KB Output is correct
4 Correct 91 ms 956 KB Output is correct
5 Correct 91 ms 1052 KB Output is correct
6 Correct 97 ms 1108 KB Output is correct
7 Correct 86 ms 1236 KB Output is correct
8 Correct 96 ms 1384 KB Output is correct
9 Correct 89 ms 1384 KB Output is correct
10 Correct 95 ms 1384 KB Output is correct
11 Correct 97 ms 1396 KB Output is correct
12 Correct 91 ms 1596 KB Output is correct
13 Correct 105 ms 1596 KB Output is correct
14 Correct 101 ms 1692 KB Output is correct
15 Correct 87 ms 1692 KB Output is correct
16 Correct 47 ms 1692 KB Output is correct
17 Correct 53 ms 1708 KB Output is correct
18 Correct 51 ms 1756 KB Output is correct
19 Correct 50 ms 1804 KB Output is correct
20 Correct 57 ms 1852 KB Output is correct
21 Correct 47 ms 1900 KB Output is correct
22 Correct 49 ms 1988 KB Output is correct
23 Correct 58 ms 2252 KB Output is correct
24 Correct 50 ms 2252 KB Output is correct
25 Correct 2 ms 2252 KB Output is correct
26 Correct 2 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 21 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -