#include<bits/stdc++.h>
using namespace std;
#define oo 1000000000000000
#define f first
#define s second
vector<int> up;
int Find(int x){
if(up[x] < 0)return x;
else{
up[x]=Find(up[x]);
return up[x];
}
}
void Union(int a, int b){
a = Find(a);
b = Find(b);
up[b]=a;
}
long long n, m;
vector<pair<pair<int, int>,pair<long long, long long>>> E;
vector<pair<int, int>> ans;
long long tim = 0, money = 0, currpos, best;
bool cmp(pair<pair<int, int>,pair<long long, long long>> a, pair<pair<int, int>,pair<long long, long long>> b){
return a.s.f*b.s.s < a.s.s*b.s.f;
}
int main(){
cin >> n >> m;
E.resize(m);
up.assign(n, -1);
for(int i = 0; i < m; i++){
cin >> E[i].f.f >> E[i].f.s >> E[i].s.f >> E[i].s.s;
}
sort(E.begin(), E.end());
for(int j = 0; j < n-1; j++){
best = oo;
for(int i = 0; i < m; i++){
if(Find(E[i].f.f) == Find(E[i].f.s))continue;
else{
if(tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f < best){
best = tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f;
currpos = i;
}
}
}
tim += E[currpos].s.f;
money += E[currpos].s.s;
Union(E[currpos].f.f, E[currpos].f.s);
ans.push_back(E[currpos].f);
}
cout << tim << " " << money << endl;
for(int i =0; i < ans.size(); i++){
cout << ans[i].f << " " << ans[i].s << endl;
}
}
Compilation message
timeismoney.cpp: In function 'int main()':
timeismoney.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i =0; i < ans.size(); i++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
8 |
Correct |
26 ms |
540 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
340 KB |
Output isn't correct |
19 |
Incorrect |
24 ms |
548 KB |
Output isn't correct |
20 |
Incorrect |
24 ms |
468 KB |
Output isn't correct |