# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
482785 | solarmagic | 시간이 돈 (balkan11_timeismoney) | C++17 | 75 ms | 924 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using db = long double;
using ll = long long;
db MAX = 1e5;
struct edge{
ll a, b, t, c;
db k;
};
ll n, m;
vector<edge> v;
vector<ll> p, sz;
ll find(ll x){
if(x == p[x]) return x;
return p[x] = find(p[x]);
}
void init(ll mid) {
fill(all(sz), 1);
iota(all(p), 0);
for (auto& [a, b, t, c, k] : v) {
k = c * mid + t * (MAX - mid);
}
sort(all(v), [](auto& a, auto& b){return a.k < b.k;});
}
ll solve(db mid){
init(mid);
ll solt = 0, solc = 0;
for (auto [a, b, t, c, k] : v) {
a = find(a), b = find(b);
if (a == b) continue;
solt += t;
solc += c;
if(sz[a] < sz[b]) swap(a, b);
sz[a] += sz[b];
p[b] = a;
}
return solt * solc;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
v.resize(m);
p.resize(n);
sz.resize(n);
for (auto& [a, b, t, c, val] : v)
cin >> a >> b >> t >> c;
db l = 0, r = MAX;
while(r - l > 1e-7) {
db m1 = (2*l + r) / 3;
db m2 = (l + 2*r) / 3;
if (solve(m1) < solve(m2)) r = m2;
else l = m1;
}
init(l);
vector<pair<ll,ll>> ans;
ll sumt = 0, sumc = 0;
for (auto [a, b, t, c, k] : v) {
a = find(a), b = find(b);
if (a == b) continue;
sumt += t;
sumc += c;
ans.emplace_back(a, b);
if(sz[a] < sz[b]) swap(a, b);
sz[a] += sz[b];
p[b] = a;
}
cout << sumt << ' ' << sumc << "\n";
for (auto [a, b] : ans) {
cout << a << ' ' << b << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |