Pagini recente » Cod sursa (job #1772876) | Cod sursa (job #961957) | Cod sursa (job #1377103) | Cod sursa (job #551048) | Cod sursa (job #761914)
Cod sursa(job #761914)
#include <cstdio>
#include <algorithm>
using namespace std;
#define nmax 200004
#define wmax 3400005
#define ll long long
int n, m, rez[nmax];
typedef struct{
int x, y, poz;
ll c1, c2;
}camp;
camp v[nmax];
int t[nmax];
int poz;
char s[wmax];
/*inline bool cmp(camp a, camp b){
if (a.c1 == b.c1){
return a.c2 > b.c2;
}
return a.c1 < b.c1;
}
*/
struct cmp{
bool operator() (const camp &a, const camp &b){
if (a.c1 == b.c1)
return a.c2 > b.c2;
return a.c1 < b.c1;
}
};
void citeste_buf(int &nr){
for(; (s[poz]<'0' || s[poz]>'9')&&s[poz]!='-'; poz++);
int semn = 1;
if (s[poz] == '-') semn = -1, ++poz;
for(; s[poz]>='0'&&s[poz]<='9';poz++){
nr = nr * 10 + (s[poz]-'0');
}
nr = nr * semn;
}
void citeste_buf2(ll &nr){
for(; (s[poz]<'0' || s[poz]>'9')&&s[poz]!='-'; poz++);
int semn = 1;
if (s[poz] == '-') semn = -1, ++poz;
for(; s[poz]>='0'&&s[poz]<='9';poz++){
nr = nr * 10 + (s[poz]-'0');
}
nr = nr * semn;
}
void citeste(){
//f >> n >> m;
//getline(f,s);
//fgets(s,wmax,stdin);
gets(s);
poz = 0;
citeste_buf(n);
citeste_buf(m);
for(int i=1; i<=m; i++){
//f >> v[i].x >> v[i].y >> v[i].c1 >> v[i].c2;
//getline(f,s);
gets(s);
poz = 0;
citeste_buf(v[i].x);
citeste_buf(v[i].y);
citeste_buf2(v[i].c1);
citeste_buf2(v[i].c2);
//scanf("%d%d%lld%lld\n", &v[i].x, &v[i].y, &v[i].c1, &v[i].c2);
v[i].poz = i;
}
sort(v+1, v+m+1, cmp());
}
inline int radacina(int x){
int cpy = x;
for(;t[x]!=0;x=t[x]);
for(;cpy!=x;){
int temp = cpy;
t[cpy] = x;
cpy = t[temp];
}
return x;
}
void uneste(int x, int y){
t[x] = y;
}
void rezolva(){
for(int i=1; i<=m; i++){
int X = radacina(v[i].x);
int Y = radacina(v[i].y);
if (X == Y) continue;
uneste(X,Y);
rez[++rez[0]] = v[i].poz;
}
//for(int i=1; i<n; i++) g << rez[i] << "\n";
for(int i=1; i<n; i++) printf("%d\n", rez[i]);
}
int main(){
freopen("lazy.in", "r", stdin);
freopen("lazy.out", "w", stdout);
citeste();
rezolva();
return 0;
}