#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 201, nbIter = 10000,inf = sqrt(LLONG_MAX/2);
int comp[N],siz[N],t[N],c[N],x[N],y[N];
int fin1=inf,fin2=inf;
vector<pair<int,int>> res;
int getComp(int node){
if (comp[node] != node) comp[node] = getComp(comp[node]);
return comp[node];
}
bool merge(int a, int b){
a = getComp(a);
b = getComp(b);
if (a != b){
if (siz[a] < siz[b]) swap(a,b);
siz[a] += siz[b];
comp[b] = a;
return true;
}
return false;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
for (int i=0; i<m; ++i){
cin >> x[i] >> y[i] >> t[i] >> c[i];
}
for (int nb=0; nb<=nbIter; ++nb){
vector<pair<int,int>> v,ans;
for (int i=0; i<m; ++i){
v.emplace_back(t[i]*(nbIter-nb)+c[i]*nb,i);
comp[i] = i;
siz[i] = 1;
}
sort(v.begin(),v.end());
int sum1 = 0, sum2 = 0;
for (auto [comp,id]:v){
if (merge(x[id],y[id])){
sum1 += t[id];
sum2 += c[id];
ans.emplace_back(x[id],y[id]);
}
}
if (sum1*sum2 < fin1*fin2){
res = ans;
fin1 = sum1;
fin2 = sum2;
}
}
cout << fin1 << ' ' << fin2 << '\n';
for (auto i:res) cout << i.first << ' ' << i.second << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
340 KB |
Output isn't correct |
2 |
Correct |
6 ms |
212 KB |
Output is correct |
3 |
Correct |
9 ms |
212 KB |
Output is correct |
4 |
Correct |
22 ms |
336 KB |
Output is correct |
5 |
Runtime error |
152 ms |
456 KB |
Execution killed with signal 11 |
6 |
Runtime error |
127 ms |
464 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
8 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
9 |
Correct |
7 ms |
212 KB |
Output is correct |
10 |
Correct |
12 ms |
212 KB |
Output is correct |
11 |
Correct |
9 ms |
324 KB |
Output is correct |
12 |
Correct |
25 ms |
212 KB |
Output is correct |
13 |
Correct |
24 ms |
332 KB |
Output is correct |
14 |
Runtime error |
159 ms |
460 KB |
Execution killed with signal 11 |
15 |
Runtime error |
129 ms |
456 KB |
Execution killed with signal 11 |
16 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
18 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
19 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
20 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |