답안 #967628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967628 2024-04-22T14:21:56 Z sano 시간이 돈 (balkan11_timeismoney) C++17
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<fstream>
#include<algorithm>
#include <iomanip>
#include<unordered_map>
#include <set>
#define ll long long
#define For(i, n) for(ll i = 0; i < n; i++)
#define ffor(i, a, n) for(ll i = a; i < n; i++)
#define rfor(i, n) for(ll i = n; i >= 0; i--)
#define rffor(i, a, n) for(ll i = n; i >= a; i--)
#define vec vector
#define ff first
#define ss second
#define pb push_back
#define pii pair<ll, ll>
#define NEK 1e18
#define mod (1e9 + 7)
#define rsz resize
#define prv 47
using namespace std;

ll mini = NEK;
ll minit = sqrt(NEK);
ll minic = sqrt(NEK);
vec<ll> odp;
vec<ll> odp_lok;
ll n;

struct hrana{
	ll x, y, t, c;
};

vec<hrana> h_pov;

struct tr {
	ll x, y, w, ind;
};

bool zorad(tr a, tr b) {
	return a.w < b.w;
}

ll otec(ll x, vec<ll>&o) {
	if (o[x] == x) return x;
	return o[x] = otec(o[x], o);
}

pii kruskal(ll k1, ll k2) {
	vec<ll> o(n);
	For(i, n) o[i] = i;
	vec<tr> h;
	ll m = h_pov.size();
	For(i, m) {
		h.push_back({ h_pov[i].x, h_pov[i].y, h_pov[i].c * k2 - h_pov[i].t * k1, i });
	}
	sort(h.begin(), h.end(), zorad);
	ll val = 0;
	ll suc_t = 0;
	ll suc_c = 0;
	For(i, m) {
		if (otec(h[i].x, o) == otec(h[i].y, o)) continue;
		val += h[i].w;
		suc_t += h_pov[h[i].ind].t;
		suc_c += h_pov[h[i].ind].c;
		o[otec(h[i].x, o)] = otec(h[i].y, o);
		odp_lok.push_back(h[i].ind);
	}
	return { suc_t, suc_c };
}

void divide(pii a, pii b) {
	ll k1 = b.ss - a.ss;
	ll k2 = b.ff - a.ff;
	pii c = kruskal(k1, k2);
	if (((b.ff - a.ff) * (c.ss - a.ss) - (b.ss - a.ss) * (c.ff - a.ff)) > 0 || ((c.ff == a.ff) && (c.ss == a.ss)) || ((c.ff == b.ff) && (c.ss == b.ss))) {
		odp_lok.clear();
		return;
	}
	if (mini > c.ff * c.ss) {
		mini = c.ff * c.ss;
		minit = c.ff;
		minic = c.ss;
		odp.clear();
		for (auto i : odp_lok) odp.push_back(i);
	}
	odp_lok.clear();
	divide(a, c);
	divide(c, b);
	return;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ifstream cin("curling.in");
	//ofstream cout("curling.out");
	cin >> n;
	ll m;
	cin >> m;
	For(i, m) {
		ll x, y, t, c;
		cin >> x >> y >> t >> c;
		h_pov.push_back({ x, y, t, c });
	}
	pii a = kruskal(-1, 0);
	if (mini > a.ff * a.ss) {
		mini = a.ff * a.ss;
		minit = a.ff;
		minic = a.ss;
		odp.clear();
		for (auto i : odp_lok) odp.push_back(i);
	}
	odp_lok.clear(); 
	pii b = kruskal(0, 1);
	if (mini > b.ff * b.ss) {
		mini = b.ff * b.ss;
		minit = b.ff;
		minic = b.ss;
		odp.clear();
		for (auto i : odp_lok) odp.push_back(i);
	}
	odp_lok.clear();
	divide(a, b);
	cout << minit << ' ' << minic << '\n';
	for (auto i : odp_lok) cout << h_pov[i].x << ' ' << h_pov[i].y << '\n';
	return 0;
}

Compilation message

timeismoney.cpp:27:12: error: 'sqrt' was not declared in this scope
   27 | ll minit = sqrt(NEK);
      |            ^~~~
timeismoney.cpp:28:12: error: 'sqrt' was not declared in this scope
   28 | ll minic = sqrt(NEK);
      |            ^~~~