Submission #1200047


Source Code Expand

#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 210000;

struct edge
{
	int u,v;
	ll w;
};

vector<ll> g[maxn];
edge g2[maxn << 1];
int p[maxn];

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

void insert(int n,int x, int y)
{
	g[x].push_back(y);
	g[1].push_back(y + (n - x + 1) * 2);
}

int id;

void add(int u, int v, ll w)
{
	g2[++id].v = v;
	g2[id].u = u;
	g2[id].w = w;
}

bool comp(const edge & a, const edge & b)
{
	return a.w < b.w;
}

int main(int argc, char * argv[])
{
	int n, q;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= q; ++i)
	{
		int a1, b1;
		ll c1;
		scanf("%d%d%lld", &a1, &b1, &c1);
		a1++;
		b1++;
		add(a1, b1, c1);
		insert(n, a1, c1 + 1);
		insert(n, b1, c1 + 2);
	}
	static set<ll> s;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < g[i].size(); ++j)
			s.insert(g[i][j] - 2 * i);
		add(i, i%n + 1, 2 * i + (*(s.begin())));
	}
	for (int i = 1; i <= n; ++i) p[i] = i;
	sort(g2 + 1, g2 + id + 1, comp);
	ll ans = 0;
	for (int i = 1; i <= id; ++i)
	{
		int u = find(g2[i].u);
		int v = find(g2[i].v);
		if (u != v)
		{
			p[u] = v;
			ans += g2[i].w;
		}
	}
	printf("%lld\n", ans);

	return 0;
}

Submission Info

Submission Time
Task G - Zigzag MST
User wrz91win
Language C++14 (GCC 5.4.1)
Score 1300
Code Size 1345 Byte
Status AC
Exec Time 680 ms
Memory 60396 KB

Compile Error

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:53:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
                       ^
./Main.cpp:58:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%lld", &a1, &b1, &c1);
                                   ^

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1300 / 1300
Status
AC × 3
AC × 36
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
all 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, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 6400 KB
01-02.txt AC 468 ms 53608 KB
01-03.txt AC 680 ms 60396 KB
01-04.txt AC 33 ms 12800 KB
01-05.txt AC 21 ms 11520 KB
01-06.txt AC 27 ms 12032 KB
01-07.txt AC 22 ms 10880 KB
01-08.txt AC 23 ms 10880 KB
01-09.txt AC 41 ms 15100 KB
01-10.txt AC 263 ms 33648 KB
01-11.txt AC 511 ms 40044 KB
01-12.txt AC 563 ms 48364 KB
01-13.txt AC 565 ms 48876 KB
01-14.txt AC 574 ms 48364 KB
01-15.txt AC 571 ms 49132 KB
01-16.txt AC 573 ms 48364 KB
01-17.txt AC 573 ms 48364 KB
01-18.txt AC 98 ms 22108 KB
01-19.txt AC 22 ms 10752 KB
01-20.txt AC 26 ms 11008 KB
01-21.txt AC 126 ms 25588 KB
01-22.txt AC 403 ms 47212 KB
01-23.txt AC 430 ms 46316 KB
01-24.txt AC 26 ms 16252 KB
01-25.txt AC 150 ms 24940 KB
01-26.txt AC 33 ms 13056 KB
01-27.txt AC 39 ms 16380 KB
01-28.txt AC 213 ms 33520 KB
01-29.txt AC 313 ms 31724 KB
01-30.txt AC 348 ms 39404 KB
sample-01.txt AC 3 ms 6400 KB
sample-02.txt AC 3 ms 6400 KB
sample-03.txt AC 3 ms 6400 KB