#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 (max(fi.first.first, fi.first.second) < max(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++)
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
5 ms |
672 KB |
Output is correct |
8 |
Correct |
9 ms |
980 KB |
Output is correct |
9 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
980 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
980 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
980 KB |
Output isn't correct |
19 |
Incorrect |
8 ms |
980 KB |
Output isn't correct |
20 |
Incorrect |
8 ms |
1004 KB |
Output isn't correct |