CODE FESTIVAL 2016 Final

Submission #992850

Source codeソースコード

#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, nQ;
int A[202020], B[202020], C[202020];

int uf[303030];

int root(int p)
{
	return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
bool join(int p, int q)
{
	p = root(p);
	q = root(q);
	if (p == q) return false;
	uf[p] += uf[q];
	uf[q] = p;
	return true;
}

int main()
{
	scanf("%d%d", &N, &nQ);
	for (int i = 0; i < nQ; ++i) {
		scanf("%d%d%d", A + i, B + i, C + i);
	}
	for (int i = 0; i < N; ++i) uf[i] = -1;

	i64 ret = 0;
	priority_queue<pair<int, pair<int, int> > > Q;
	for (int i = 0; i < nQ; ++i) {
		Q.push({ -C[i],{ A[i], B[i] } });
		Q.push({ -C[i] - 1,{ B[i], (1 + A[i]) % N } });
	}
	while (!Q.empty()) {
		auto a = Q.top(); Q.pop();
		int cost = -a.first;
		int p = a.second.first, q = a.second.second;
		if (!join(p, q)) continue;
		ret += cost;
		Q.push({ -(cost + 2), {(p + 1) % N, (q + 1) % N} });

	}

	printf("%lld\n", ret);

	return 0;
}

Submission

Task問題 G - Zigzag MST
User nameユーザ名 semiexp feat. GUMI
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1300
Source lengthソースコード長 1300 Byte
File nameファイル名
Exec time実行時間 201 ms
Memory usageメモリ使用量 9712 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &nQ);
^
./Main.cpp:43:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", A + i, B + i, C + i);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt,sample-03.txt
all 1300 / 1300 sample-01.txt,sample-02.txt,sample-03.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 3 ms 256 KB
01-02.txt AC 129 ms 8816 KB
01-03.txt AC 160 ms 9712 KB
01-04.txt AC 8 ms 1024 KB
01-05.txt AC 9 ms 1024 KB
01-06.txt AC 11 ms 1024 KB
01-07.txt AC 12 ms 1024 KB
01-08.txt AC 19 ms 1152 KB
01-09.txt AC 32 ms 1728 KB
01-10.txt AC 101 ms 5364 KB
01-11.txt AC 157 ms 9200 KB
01-12.txt AC 177 ms 9584 KB
01-13.txt AC 179 ms 9712 KB
01-14.txt AC 178 ms 9712 KB
01-15.txt AC 179 ms 9712 KB
01-16.txt AC 178 ms 9712 KB
01-17.txt AC 178 ms 9712 KB
01-18.txt AC 106 ms 9712 KB
01-19.txt AC 9 ms 1024 KB
01-20.txt AC 28 ms 1152 KB
01-21.txt AC 81 ms 3320 KB
01-22.txt AC 201 ms 9712 KB
01-23.txt AC 199 ms 9712 KB
01-24.txt AC 14 ms 1728 KB
01-25.txt AC 137 ms 9712 KB
01-26.txt AC 8 ms 1024 KB
01-27.txt AC 27 ms 1600 KB
01-28.txt AC 123 ms 5748 KB
01-29.txt AC 169 ms 9328 KB
01-30.txt AC 187 ms 9712 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB
sample-03.txt AC 3 ms 256 KB