Submission #1818024


Source Code Expand

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2e5 + 7;
int prv[N], c[N];

struct TEdge {
	int u, v, c;
} e[N];

inline bool operator < (const TEdge &e1, const TEdge &e2) {
	return e1.c < e2.c;
}

int root(int u) {
	return prv[u] ? prv[u] = root(prv[u]) : u;
}

bool dsu(int u, int v) {
	return (u = root(u)) != (v = root(v)) ? prv[u] = v, true : false;
}

int main() {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &c[i]);
		if (!c[i]) c[i] = k + i;
	}
	for (int i = 0; i < m; ++i)
		scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].c);
	sort(e, e + m);
	int count_edge = 0;
	long long res = 0;
	for (int i = 0; i < m; ++i)
		if (dsu(c[e[i].u], c[e[i].v])) {
			res += e[i].c;
			if (++count_edge == k - 1) {
				printf("%lld", res);
				return 0;
			}
		}
	printf("-1");
	return 0;
}

Submission Info

Submission Time
Task A - Colorful MST
User ArtemisChillwind
Language C++14 (GCC 5.4.1)
Score 700
Code Size 889 Byte
Status AC
Exec Time 55 ms
Memory 2560 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:24:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n, m, k; scanf("%d%d%d", &n, &m, &k);
                                          ^
./Main.cpp:26:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &c[i]);
                     ^
./Main.cpp:30:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].c);
                                             ^

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 0 / 0 100 / 100 100 / 100 200 / 200 300 / 300
Status
AC × 4
AC × 7
AC × 12
AC × 7
AC × 28
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt
Subtask1 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt
Subtask2 s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s2_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt
Subtask3 00_example_02.txt, s3_13.txt, s3_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt
Subtask4 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s2_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s3_13.txt, s3_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt, s4_19.txt, s4_20.txt, s4_21.txt, s4_22.txt, s4_23.txt, s4_24.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 128 KB
00_example_02.txt AC 1 ms 128 KB
00_example_03.txt AC 1 ms 128 KB
00_example_04.txt AC 1 ms 128 KB
s1_01.txt AC 1 ms 128 KB
s1_02.txt AC 44 ms 2176 KB
s1_03.txt AC 1 ms 128 KB
s1_04.txt AC 1 ms 128 KB
s1_05.txt AC 22 ms 1408 KB
s1_06.txt AC 45 ms 2176 KB
s2_07.txt AC 6 ms 384 KB
s2_08.txt AC 46 ms 2176 KB
s2_09.txt AC 32 ms 1408 KB
s2_10.txt AC 30 ms 1280 KB
s2_11.txt AC 41 ms 1792 KB
s2_12.txt AC 40 ms 1792 KB
s3_13.txt AC 6 ms 512 KB
s3_14.txt AC 43 ms 2176 KB
s3_15.txt AC 31 ms 1664 KB
s3_16.txt AC 30 ms 1536 KB
s3_17.txt AC 43 ms 2176 KB
s3_18.txt AC 38 ms 2176 KB
s4_19.txt AC 6 ms 512 KB
s4_20.txt AC 40 ms 2176 KB
s4_21.txt AC 32 ms 1664 KB
s4_22.txt AC 33 ms 1664 KB
s4_23.txt AC 55 ms 2560 KB
s4_24.txt AC 41 ms 2304 KB