답안 #469283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469283 2021-08-31T10:50:51 Z Autron 시간이 돈 (balkan11_timeismoney) C++14
100 / 100
110 ms 916 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct edge{
	int a, b, c, t;
	long double val;
	
	bool operator<(const edge& ot) const{
		return val<ot.val;
	}

};

int n, m;
vector<edge> v;
vector<int> fat, sz;
int solc, solt;
vector<edge> ans;

int get(int x){
	if(x==fat[x]) return x;
	return fat[x]=get(fat[x]);
}

void join(edge x){
	int a=get(x.a), b=get(x.b);
	if(a==b) return;
	solc+=x.c;
	solt+=x.t;
	ans.push_back(x);	
	if(sz[a]<sz[b]) swap(a, b);
	sz[a]+=sz[b];
	fat[b]=a;
}

int check(long double rat){
	for(int i=0;i<n;++i) fat[i]=i, sz[i]=1;
	for(int i=0;i<m;++i) v[i].val=v[i].c*rat+v[i].t*((long double)1e5-rat);
	sort(v.begin(), v.end());
	solc=0, solt=0;
	ans.clear();
	for(int i=0;i<m;++i){
		join(v[i]);
	}
	return solc*solt;
}

int32_t main(){
	cin>>n>>m;
	v.resize(m);
	for(int i=0;i<m;++i){
		cin>>v[i].a>>v[i].b>>v[i].t>>v[i].c;
	}
	fat.resize(n), sz.resize(n);
	long double st=0, dr=1e5;
	while((dr-st)>1e-7){
		long double m1=(2*st+dr)/3;
		long double m2=(st+2*dr)/3;
		if(check(m1)<check(m2)) dr=m2;
		else st=m1;
	}
	check(st);
	int sumc=0, sumt=0;
	for(auto it:ans){
		sumc+=it.c, sumt+=it.t;
	}
	cout<<sumt<<" "<<sumc<<"\n";
	for(auto it:ans) cout<<it.a<<" "<<it.b<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 17 ms 332 KB Output is correct
8 Correct 89 ms 844 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 4 ms 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 19 ms 332 KB Output is correct
17 Correct 20 ms 332 KB Output is correct
18 Correct 19 ms 440 KB Output is correct
19 Correct 110 ms 916 KB Output is correct
20 Correct 106 ms 812 KB Output is correct