Submission #637885

# Submission time Handle Problem Language Result Execution time Memory
637885 2022-09-03T13:48:20 Z google timeismoney (balkan11_timeismoney) C++17
70 / 100
2000 ms 596 KB
#include<bits/stdc++.h>
using namespace std;
const int siz = 205;
int p[siz],sz[siz];
int findp(int a){
	if (p[a] == a) return a;
	return p[a] = findp(p[a]);
}
void unite(int a, int b){
	if (sz[a] < sz[b]) swap(a,b);
	p[b] = a;
	sz[a] += sz[b];
}
int gcd(int a, int b){
	if (a < b) swap(a,b);
	return b?gcd(b,a%b):a;
}
int I,J;
bool cmp(pair<pair<int,int>,pair<int,int>> & a, pair<pair<int,int>,pair<int,int>> &b){
	return a.second.first*I+a.second.second*J < b.second.first*I+b.second.second*J;
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n,m; cin >> n >> m;
	vector<pair<pair<int,int>,pair<int,int>>> v(m);
	pair<pair<int,int>,vector<pair<int,int>>> ans;
	for (int i = 0;i<m;i++) cin >> v[i].first.first >> v[i].first.second >> v[i].second.first >> v[i].second.second;
	long long best = LLONG_MAX;
	for (I = 1;I<255;I++){
		for (J = 1;J<255;J++){
			if (I != 1 && J != 1 && gcd(I,J) == 1) continue;
			for (int i = 0;i<n;i++) {p[i] = i;sz[i] = 1;}
			sort(v.begin(),v.end(),cmp);
			int cnt1 = 0,cnt2 = 0;
			vector<pair<int,int>> e;
			for (int i = 0;i<m;i++){
				auto [a,b] = v[i].first;
				a = findp(a);
				b = findp(b);
				if (a == b) continue;
				e.push_back(v[i].first);
				unite(a,b);
				cnt1 += v[i].second.first;
				cnt2 += v[i].second.second;
			}
			if (1LL*cnt1*cnt2 < best){
				best = 1LL*cnt1*cnt2;
				ans.first.first = cnt1;
				ans.first.second = cnt2;
				ans.second.clear();
				for (auto &a:e) ans.second.push_back(a);
			}
		}
	}
	cout << ans.first.first << ' ' << ans.first.second << '\n';
	for (auto [a,b]:ans.second) cout << a << ' ' << b << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 187 ms 332 KB Output is correct
2 Correct 15 ms 324 KB Output is correct
3 Correct 21 ms 212 KB Output is correct
4 Correct 67 ms 324 KB Output is correct
5 Correct 368 ms 320 KB Output is correct
6 Correct 291 ms 332 KB Output is correct
7 Correct 1985 ms 372 KB Output is correct
8 Execution timed out 2071 ms 596 KB Time limit exceeded
9 Correct 16 ms 212 KB Output is correct
10 Correct 41 ms 212 KB Output is correct
11 Correct 23 ms 328 KB Output is correct
12 Correct 73 ms 212 KB Output is correct
13 Correct 76 ms 304 KB Output is correct
14 Correct 460 ms 332 KB Output is correct
15 Correct 377 ms 340 KB Output is correct
16 Execution timed out 2066 ms 340 KB Time limit exceeded
17 Execution timed out 2080 ms 340 KB Time limit exceeded
18 Execution timed out 2082 ms 468 KB Time limit exceeded
19 Execution timed out 2080 ms 596 KB Time limit exceeded
20 Execution timed out 2076 ms 596 KB Time limit exceeded