답안 #223927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223927 2020-04-16T21:26:35 Z super_j6 시간이 돈 (balkan11_timeismoney) C++14
20 / 100
2000 ms 56736 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, int>
#define f first
#define s second

const int maxn = 200, maxm = 10000;
int n, m;
int it[maxm], u[maxm], v[maxm], a[maxm], b[maxm];
int par[maxn], rnk[maxn];
vector<pi> ans;

int find(int x){
	return x == par[x] ? x : par[x] = find(par[x]);
}

pi mst(ll x, ll y, bool t = 0){
	for(int i = 0; i < n; i++) par[i] = i, rnk[i] = 0;
	sort(it, it + m, [&](int i, int j){
		return a[i] * x + b[i] * y < a[j] * x + b[j] * y;
	});

	pi ret = {0, 0};
	for(int i = 0; i < m; i++){
		int j = it[i];
		int w = find(u[j]), z = find(v[j]);
		if(w != z){
			ret.f += a[j], ret.s += b[j];
			if(t) ans.push_back({u[j], v[j]});
			if(rnk[w] < rnk[z]) swap(w, z);
			rnk[w] += rnk[w] == rnk[z];
			par[z] = w;
		}
	}
	
	return ret;
}

pi solve(pi l, pi r){
	pi p = mst(r.s - l.s, l.f - r.f);
	if(p == l || p == r) return l.f * l.s < r.f * r.s ? l : r;
	return min(solve(l, p), solve(p, r));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	
	for(int i = 0; i < m; i++){
		cin >> u[i] >> v[i] >> a[i] >> b[i];
		it[i] = i;
	}
	
	pi ret = solve(mst(0, 1), mst(1, 0));
	mst(ret.s, ret.f, 1);
	
	cout << ret.f << " " << ret.s << endl;
	for(pi i : ans) cout << i.f << " " << i.s << endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Execution timed out 2080 ms 56736 KB Time limit exceeded
5 Execution timed out 2083 ms 11844 KB Time limit exceeded
6 Execution timed out 2084 ms 12692 KB Time limit exceeded
7 Execution timed out 2084 ms 2996 KB Time limit exceeded
8 Execution timed out 2083 ms 1528 KB Time limit exceeded
9 Correct 4 ms 384 KB Output is correct
10 Incorrect 4 ms 384 KB Output isn't correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Incorrect 5 ms 384 KB Output isn't correct
13 Incorrect 5 ms 384 KB Output isn't correct
14 Incorrect 9 ms 384 KB Output isn't correct
15 Incorrect 8 ms 384 KB Output isn't correct
16 Execution timed out 2085 ms 1376 KB Time limit exceeded
17 Execution timed out 2087 ms 1528 KB Time limit exceeded
18 Execution timed out 2084 ms 1440 KB Time limit exceeded
19 Execution timed out 2088 ms 1028 KB Time limit exceeded
20 Execution timed out 2084 ms 1052 KB Time limit exceeded