//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n,m;
llo par[201];
llo find(llo no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++){
par[i]=i;
}
vector<pair<pair<llo,llo>,pair<llo,llo>>> ed;
for(llo i=0;i<m;i++){
llo aa,bb,cc,dd;
cin>>aa>>bb>>cc>>dd;
ed.pb({{cc,dd},{aa,bb}});
}
sort(ed.begin(),ed.end());
for(int i=0;i<m;i++){
swap(ed[i].a,ed[i].b);
}
vector<pair<llo,llo>> ans;
llo su=0;
llo su2=0;
for(auto j:ed){
llo x=find(j.a.a);
llo y=find(j.a.b);
if(x!=y){
par[x]=y;
su+=j.b.a;
su2+=j.b.b;
ans.pb(j.a);
}
}
cout<<su<<" "<<su2<<endl;
for(auto j:ans){
cout<<j.a<<" "<<j.b<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
1008 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
19 |
Incorrect |
6 ms |
1008 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
1008 KB |
Output isn't correct |