Pagini recente » Cod sursa (job #1252144) | Cod sursa (job #3191486) | Cod sursa (job #2233541) | Cod sursa (job #828631) | Cod sursa (job #2937464)
#include <bits/stdc++.h>
#define N 200005
#define pb push_back
using namespace std;
ifstream fin("lazy.in");
ofstream fout("lazy.out");
int n, m, cost;
vector<pair<int, pair<int, pair<int, int> > > >g;
map<pair<int, int>, int>mrk;
int t[N];
void read() {
int x, y, z, t;
fin >> n >> m;
for (int i = 1; i <= m; ++i) {
fin >> x >> y >> z >> t;
g.pb({ z,{t,{x,y}} });
mrk[{x, y}] = i;
}
}
inline bool cmp(pair<int, pair<int, pair<int, int> > > A, pair<int, pair<int, pair<int, int> > > B) {
if (A.first == B.first)
return A.second.first > B.second.first;
return A.first < B.first;
}
int Find(int x) {
int root = x, y;
while (t[root])
root = t[root];
while (x != root) {
y = t[x];
t[x] = root;
x = y;
}
return root;
}
void Union(int x, int y) {
t[y] = x;
}
void solve() {
sort(g.begin(), g.end(), cmp);
for (int i = 0; i < g.size(); ++i) {
int r1 = Find(g[i].second.second.first), r2 = Find(g[i].second.second.second);
if (r1 != r2) {
Union(r1, r2);
cost += g[i].first;
fout << mrk[{g[i].second.second.first, g[i].second.second.second}] << "\n";
}
}
}
int main() {
read();
solve();
return 0;
}