Submission #231145

#TimeUsernameProblemLanguageResultExecution timeMemory
231145summitweitimeismoney (balkan11_timeismoney)C++17
40 / 100
18 ms640 KiB
#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 timeMemoryGrader output
Fetching results...