# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
231145 | summitwei | timeismoney (balkan11_timeismoney) | C++17 | 18 ms | 640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define INF 0x3f3f3f3f
#define MOD 30013
#define f first
#define s second
#define pb push_back
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define F0R(i, a) for(int i=0; i<a; ++i)
#define MN 10005
int n, m;
pair<int, pii> ree[MN];
int dsu[MN];
int fd(int x){
if(dsu[x] < 0) return x;
return dsu[x]=fd(dsu[x]);
}
bool jn(int x, int y){
x = fd(x); y = fd(y);
if(x == y) return false;
if(dsu[x] > dsu[y]) swap(x, y);
dsu[x] += dsu[y];
dsu[y] = x;
return true;
}
vpii used;
int main(){
cin >> n >> m;
F0R(i, m){
cin >> ree[i].s.f >> ree[i].s.s >> ree[i].f >> ree[i].f;
}
sort(ree, ree+m);
F0R(i, n) dsu[i] = -1;
int tot = 0;
F0R(i, m){
if(jn(ree[i].s.f, ree[i].s.s)){
tot += ree[i].f;
used.pb(ree[i].s);
}
}
cout << tot << " " << tot << "\n";
for(auto u : used) cout << u.f << " " << u.s << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |