답안 #22617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22617 2017-04-30T05:58:26 Z AcornCkiGs14004Team(#953, gs14004, cki86201, dotorya) Logistical Metropolis (KRIII5_LM) C++11
2 / 7
79 ms 2060 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long lint;

const int MAXN = 1005;
struct disj{
	int pa[MAXN], sz[MAXN];
	void init(int n){
		for(int i=0; i<=n; i++){
			pa[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p;
		sz[p] += sz[q];
		return 1;
	}
}disj;

struct edg{int s, e, x;}e[3005];

int n, m;

int main(){
	cin >> n >> m;
	for(int i=0; i<m; i++){
		cin >> e[i].s >> e[i].e >> e[i].x;
	}
	sort(e, e+m, [&](const edg &a, const edg &b){
		return a.x < b.x;
	});
	for(int i=1; i<=n; i++){
		int ans = 0;
		disj.init(n);
		for(int j=0; j<m; j++){
			if(e[j].s == i || e[j].e == i){
				if(disj.uni(e[j].s, e[j].e)){
				ans += e[j].x;
				}
			}
		}
		for(int j=0; j<m; j++){
			if(disj.uni(e[j].s, e[j].e)) ans += e[j].x;
		}
		cout << ans << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 2060 KB Output is correct
2 Correct 63 ms 2060 KB Output is correct
3 Correct 63 ms 2060 KB Output is correct
4 Correct 49 ms 2060 KB Output is correct
5 Correct 59 ms 2060 KB Output is correct
6 Correct 66 ms 2060 KB Output is correct
7 Correct 66 ms 2060 KB Output is correct
8 Correct 73 ms 2060 KB Output is correct
9 Correct 69 ms 2060 KB Output is correct
10 Correct 63 ms 2060 KB Output is correct
11 Correct 66 ms 2060 KB Output is correct
12 Correct 63 ms 2060 KB Output is correct
13 Correct 79 ms 2060 KB Output is correct
14 Correct 69 ms 2060 KB Output is correct
15 Correct 73 ms 2060 KB Output is correct
16 Correct 29 ms 2060 KB Output is correct
17 Correct 23 ms 2060 KB Output is correct
18 Correct 26 ms 2060 KB Output is correct
19 Correct 33 ms 2060 KB Output is correct
20 Correct 29 ms 2060 KB Output is correct
21 Correct 33 ms 2060 KB Output is correct
22 Correct 29 ms 2060 KB Output is correct
23 Correct 33 ms 2060 KB Output is correct
24 Correct 26 ms 2060 KB Output is correct
25 Correct 0 ms 2060 KB Output is correct
26 Correct 0 ms 2060 KB Output is correct
27 Correct 0 ms 2060 KB Output is correct
28 Correct 16 ms 2060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -