52482023-04-24 02:41:24SleepyOverlordMobilNet (50 pont)cpp17Elfogadva 50/5079ms18636 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

int n;
VPII a;
vector < tuple <int, int, int> > edges;
UM<int, VI> byY;
VI p, sz;

int getRoot(int node)
{
	if (p[node] != node) return p[node] = getRoot(p[node]);
	else return node;
}

bool unite(int i1, int i2)
{
	int r1 = getRoot(i1);
	int r2 = getRoot(i2);
	if (r1 == r2) return false;
	if (sz[r1] < sz[r2]) p[r1] = r2, sz[r2] += sz[r1];
	else p[r2] = r1, sz[r1] += sz[r2];
	return true;
}

int main()
{
	cin >> n;
	a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
	sort(a.BG + 1, a.EN);
	byY[a[1].Y].PB(1);
	FOR(i, 2, n)
	{
		byY[a[i].Y].PB(i);
		if (a[i].X == a[i - 1].X) edges.PB({a[i].Y - a[i - 1].Y, i, i - 1});
	}
	for (auto& [y, v] : byY)
		FOR(i, 1, v.SZ - 1)
		{
			int i1 = v[i - 1];
			int i2 = v[i];
			edges.PB({a[i2].X - a[i1].X, i1, i2});
		}

	sort(ALL(edges));
	p.RS(n + 1), sz.RS(n + 1);
	FOR(i, 1, n) p[i] = i, sz[i] = 1;

	int cnt = n, i = 0, last = n, prevCost = -1;
	while (cnt > 1)
	{
		auto [cost, u, v] = edges[i++];
		if (cost != prevCost) last = cnt;
		if (unite(u, v)) --cnt;
		prevCost = cost;
	}

	auto [cost, u, v] = edges[i - 1];
	cout << cost << endl;
	cout << last - 1 << endl;

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1816 KiB
2Elfogadva0/08ms2724 KiB
3Elfogadva2/23ms2372 KiB
4Elfogadva2/23ms2544 KiB
5Elfogadva2/23ms2764 KiB
6Elfogadva2/23ms2860 KiB
7Elfogadva2/23ms3164 KiB
8Elfogadva2/24ms3508 KiB
9Elfogadva2/24ms3944 KiB
10Elfogadva2/26ms4400 KiB
11Elfogadva2/28ms4980 KiB
12Elfogadva2/212ms5740 KiB
13Elfogadva3/317ms6172 KiB
14Elfogadva3/325ms7040 KiB
15Elfogadva3/332ms8896 KiB
16Elfogadva3/339ms9776 KiB
17Elfogadva3/354ms11732 KiB
18Elfogadva3/354ms12104 KiB
19Elfogadva3/364ms13936 KiB
20Elfogadva3/378ms15388 KiB
21Elfogadva3/379ms17904 KiB
22Elfogadva3/375ms18636 KiB