#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m, dsu[210];
vector <pair< pair<int, int>, pair<int, int> > > vec;
vector <pair<int, int> > ans;
int dsu_get(int v){
if (dsu[v] == v)
return v;
return dsu[v] = dsu_get(dsu[v]);
}
int dsu_connct(int a, int b){
int aa = a, bb = b;
a = dsu_get(a);
b = dsu_get(b);
if (a == b)
return 0;
dsu[b] = a;
return 1;
}
bool cmp(pair<pair<int, int>, pair<int, int> > fi, pair<pair<int, int>, pair<int, int> > se){
return (fi.first.first+fi.first.second < se.first.first+se.first.second);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for (int i = 0; i <= n; i++)
dsu[i] = i;
for (int i = 1; i <= m; i++){
int a, b, c, d;
cin >> a >> b >> c >> d;
vec.push_back({{c, d}, {a, b}});
}
int ans1 = 0, ans2 = 0;
sort(vec.begin(), vec.end(), cmp);
for (int i = 0; i < vec.size(); i++){
int a = vec[i].second.first, b = vec[i].second.second, c = vec[i].first.first, d = vec[i].first.second;
if (dsu_connct(a, b) == 1){
ans.push_back({a, b});
ans1 += c;
ans2 += d;
}
}
cout << ans1 << ' ' << ans2 << endl;
for (int i = 0; i < ans.size(); i++)
cout << ans[i].first << ' ' << ans[i].second << endl;
}
Compilation message
timeismoney.cpp: In function 'int dsu_connct(int, int)':
timeismoney.cpp:19:9: warning: unused variable 'aa' [-Wunused-variable]
int aa = a, bb = b;
^~
timeismoney.cpp:19:17: warning: unused variable 'bb' [-Wunused-variable]
int aa = a, bb = b;
^~
timeismoney.cpp: In function 'int main()':
timeismoney.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vec.size(); i++){
~~^~~~~~~~~~~~
timeismoney.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
612 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
752 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
4 ms |
784 KB |
Output is correct |
8 |
Correct |
9 ms |
1340 KB |
Output is correct |
9 |
Correct |
3 ms |
1340 KB |
Output is correct |
10 |
Incorrect |
3 ms |
1340 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1340 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1340 KB |
Output isn't correct |
13 |
Correct |
2 ms |
1340 KB |
Output is correct |
14 |
Incorrect |
4 ms |
1340 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
1340 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
1340 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
1340 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
1340 KB |
Output isn't correct |
19 |
Incorrect |
10 ms |
1680 KB |
Output isn't correct |
20 |
Incorrect |
9 ms |
1880 KB |
Output isn't correct |