Submission #242624


Source Code Expand

Copy
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 100001
#define MAX_M 200001

int N, M;
int E = 0;
struct edge{ int u, v, cost; };
edge es[MAX_M + MAX_N + 1];
int Rank[MAX_N + 1];
int par[MAX_N + 1];

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

void init(int n){
	for (int i = 0; i <= n; i++){
		Rank[i] = 0;
		par[i] = i;
	}
}

int find(int x){
	if (par[x] == x)
		return x;
	else
		return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);

	if (x == y)
		return;

	if (Rank[x] < Rank[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if (Rank[x] == Rank[y])
			Rank[x]++;
	}

}

bool same(int x, int y){
	return find(x) == find(y);
}

int solve(){
	sort(es, es + E, comp);
	init(N);
	int res = 0;
	for (int i = 0; i < E; i++){
		edge e = es[i];
		if (!same(e.u, e.v)){
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main() {

	cin >> N >> M;
	for (int i = 0; i < N; i++){
		int c;
		cin >> c;
		es[i].u = N;
		es[i].v = i;
		es[i].cost = c;
		E++;
	}

	for (int i = 0; i < M; i++){
		cin >> es[E].u >> es[E].v >> es[E].cost;
		es[E].u--;
		es[E].v--;
		E++;
	}

	cout << solve() << endl;

	return 0;
}

Submission Info

Submission Time
Task C - 高橋君と国家
User taketake0609
Language C++ (G++ 4.6.4)
Score 0
Code Size 1798 Byte
Status
Exec Time 493 ms
Memory 5152 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt
Subtask1 0 / 10 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt
Subtask2 0 / 20 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt
Subtask3 0 / 30 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt, subtask3-01.txt, subtask3-02.txt, subtask3-03.txt, subtask3-04.txt, subtask3-05.txt, subtask3-06.txt, subtask3-07.txt, subtask3-08.txt, subtask3-09.txt, subtask3-10.txt, subtask3-11.txt, subtask3-12.txt, subtask3-13.txt, subtask3-14.txt, subtask3-15.txt, subtask3-16.txt, subtask3-17.txt, subtask3-18.txt, subtask3-19.txt, subtask3-20.txt, subtask3-21.txt, subtask3-22.txt, subtask3-23.txt, subtask3-24.txt, subtask3-25.txt, subtask3-26.txt, subtask3-27.txt, subtask3-28.txt, subtask3-29.txt, subtask3-30.txt
Subtask4 0 / 40 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt, subtask3-01.txt, subtask3-02.txt, subtask3-03.txt, subtask3-04.txt, subtask3-05.txt, subtask3-06.txt, subtask3-07.txt, subtask3-08.txt, subtask3-09.txt, subtask3-10.txt, subtask3-11.txt, subtask3-12.txt, subtask3-13.txt, subtask3-14.txt, subtask3-15.txt, subtask3-16.txt, subtask3-17.txt, subtask3-18.txt, subtask3-19.txt, subtask3-20.txt, subtask3-21.txt, subtask3-22.txt, subtask3-23.txt, subtask3-24.txt, subtask3-25.txt, subtask3-26.txt, subtask3-27.txt, subtask3-28.txt, subtask3-29.txt, subtask3-30.txt, subtask4-01.txt, subtask4-02.txt, subtask4-03.txt, subtask4-04.txt, subtask4-05.txt, subtask4-06.txt, subtask4-07.txt, subtask4-08.txt, subtask4-09.txt, subtask4-10.txt, subtask4-11.txt, subtask4-12.txt, subtask4-13.txt, subtask4-14.txt, subtask4-15.txt, subtask4-16.txt, subtask4-17.txt, subtask4-18.txt, subtask4-19.txt, subtask4-20.txt, subtask4-21.txt, subtask4-22.txt, subtask4-23.txt, subtask4-24.txt, subtask4-25.txt, subtask4-26.txt, subtask4-27.txt, subtask4-28.txt, subtask4-29.txt, subtask4-30.txt
Case Name Status Exec Time Memory
subtask0-sample-01.txt 22 ms 928 KB
subtask0-sample-02.txt 24 ms 808 KB
subtask0-sample-03.txt 24 ms 728 KB
subtask1-01.txt 23 ms 920 KB
subtask1-02.txt 22 ms 928 KB
subtask1-03.txt 23 ms 928 KB
subtask1-04.txt 23 ms 928 KB
subtask1-05.txt 22 ms 928 KB
subtask1-06.txt 23 ms 732 KB
subtask1-07.txt 25 ms 776 KB
subtask1-08.txt 24 ms 924 KB
subtask1-09.txt 24 ms 932 KB
subtask1-10.txt 22 ms 932 KB
subtask1-11.txt 23 ms 920 KB
subtask1-12.txt 23 ms 804 KB
subtask1-13.txt 25 ms 760 KB
subtask1-14.txt 22 ms 932 KB
subtask1-15.txt 22 ms 796 KB
subtask1-16.txt 23 ms 804 KB
subtask1-17.txt 22 ms 800 KB
subtask1-18.txt 23 ms 928 KB
subtask1-19.txt 22 ms 920 KB
subtask1-20.txt 24 ms 800 KB
subtask1-21.txt 24 ms 800 KB
subtask1-22.txt 25 ms 760 KB
subtask1-23.txt 24 ms 928 KB
subtask1-24.txt 26 ms 768 KB
subtask1-25.txt 25 ms 928 KB
subtask1-26.txt 24 ms 804 KB
subtask1-27.txt 24 ms 800 KB
subtask1-28.txt 23 ms 736 KB
subtask1-29.txt 24 ms 800 KB
subtask1-30.txt 23 ms 920 KB
subtask2-01.txt 27 ms 772 KB
subtask2-02.txt 23 ms 932 KB
subtask2-03.txt 22 ms 800 KB
subtask2-04.txt 23 ms 932 KB
subtask2-05.txt 23 ms 920 KB
subtask2-06.txt 27 ms 932 KB
subtask2-07.txt 23 ms 928 KB
subtask2-08.txt 23 ms 924 KB
subtask2-09.txt 22 ms 800 KB
subtask2-10.txt 22 ms 920 KB
subtask2-11.txt 23 ms 928 KB
subtask2-12.txt 23 ms 932 KB
subtask2-13.txt 22 ms 804 KB
subtask2-14.txt 24 ms 796 KB
subtask2-15.txt 22 ms 924 KB
subtask2-16.txt 24 ms 800 KB
subtask2-17.txt 22 ms 924 KB
subtask2-18.txt 22 ms 796 KB
subtask2-19.txt 22 ms 928 KB
subtask2-20.txt 24 ms 924 KB
subtask2-21.txt 23 ms 748 KB
subtask2-22.txt 24 ms 928 KB
subtask2-23.txt 23 ms 800 KB
subtask2-24.txt 23 ms 932 KB
subtask2-25.txt 24 ms 804 KB
subtask2-26.txt 22 ms 804 KB
subtask2-27.txt 26 ms 924 KB
subtask2-28.txt 24 ms 932 KB
subtask2-29.txt 25 ms 916 KB
subtask2-30.txt 24 ms 796 KB
subtask3-01.txt 25 ms 920 KB
subtask3-02.txt 25 ms 764 KB
subtask3-03.txt 26 ms 924 KB
subtask3-04.txt 27 ms 796 KB
subtask3-05.txt 28 ms 804 KB
subtask3-06.txt 27 ms 928 KB
subtask3-07.txt 27 ms 932 KB
subtask3-08.txt 28 ms 800 KB
subtask3-09.txt 29 ms 808 KB
subtask3-10.txt 30 ms 800 KB
subtask3-11.txt 30 ms 920 KB
subtask3-12.txt 28 ms 920 KB
subtask3-13.txt 32 ms 916 KB
subtask3-14.txt 34 ms 924 KB
subtask3-15.txt 33 ms 924 KB
subtask3-16.txt 35 ms 936 KB
subtask3-17.txt 34 ms 936 KB
subtask3-18.txt 35 ms 924 KB
subtask3-19.txt 35 ms 864 KB
subtask3-20.txt 35 ms 940 KB
subtask3-21.txt 35 ms 940 KB
subtask3-22.txt 35 ms 940 KB
subtask3-23.txt 38 ms 884 KB
subtask3-24.txt 34 ms 940 KB
subtask3-25.txt 35 ms 940 KB
subtask3-26.txt 35 ms 928 KB
subtask3-27.txt 35 ms 932 KB
subtask3-28.txt 34 ms 932 KB
subtask3-29.txt 36 ms 936 KB
subtask3-30.txt 34 ms 924 KB
subtask4-01.txt 46 ms 1128 KB
subtask4-02.txt 54 ms 1136 KB
subtask4-03.txt 63 ms 1184 KB
subtask4-04.txt 207 ms 2524 KB
subtask4-05.txt 283 ms 3376 KB
subtask4-06.txt 392 ms 4520 KB
subtask4-07.txt 380 ms 4392 KB
subtask4-08.txt 257 ms 3620 KB
subtask4-09.txt 333 ms 4064 KB
subtask4-10.txt 489 ms 5088 KB
subtask4-11.txt 487 ms 5012 KB
subtask4-12.txt 473 ms 4972 KB
subtask4-13.txt 486 ms 5032 KB
subtask4-14.txt 484 ms 5084 KB
subtask4-15.txt 474 ms 5092 KB
subtask4-16.txt 472 ms 5036 KB
subtask4-17.txt 473 ms 5088 KB
subtask4-18.txt 493 ms 5036 KB
subtask4-19.txt 484 ms 5032 KB
subtask4-20.txt 484 ms 5016 KB
subtask4-21.txt 484 ms 4988 KB
subtask4-22.txt 485 ms 5036 KB
subtask4-23.txt 476 ms 5024 KB
subtask4-24.txt 480 ms 5152 KB
subtask4-25.txt 473 ms 5028 KB
subtask4-26.txt 486 ms 5032 KB
subtask4-27.txt 482 ms 5032 KB
subtask4-28.txt 487 ms 5024 KB
subtask4-29.txt 475 ms 5024 KB
subtask4-30.txt 484 ms 5032 KB