Pagini recente » Cod sursa (job #2017473) | Cod sursa (job #431680) | Cod sursa (job #3139932) | Cod sursa (job #1242368) | Cod sursa (job #1220853)
#include <fstream>
#include <algorithm>
using namespace std;
const int N = 1 + 2e5;
struct Mare{
unsigned long long A, B;
bool sgn;
Mare(long long x = 0, long long y = 0){
if (x == 0 || y == 0){
sgn = true;
A = B = 0;
} else {
if (x < 0){
x = -x;
sgn ^= 1;
}
if (y < 0){
y = -y;
sgn ^= 1;
}
long long a = x >> 30, b = x & 0x3fffffff;
long long c = y >> 30, d = y & 0x3fffffff;
long long mid = a * d + b * c;
A = a * c + (mid >> 30);
B = b * d + (mid & 0x3fffffff);
}
}
inline bool operator<(const Mare& M) const {
if (sgn != M.sgn)
return sgn < M.sgn;
if (A != M.A)
return A < M.A;
return B < M.B;
}
};
struct Edge{
int ind, x, y;
long long a;
Mare b;
Edge(int ind = 0, int x = 0, int y = 0, long long A = 0, long long B = 0) :
ind(ind),
x(x),
y(y),
a(A),
b(A, B)
{}
inline bool operator<(const Edge& E) const {
if (a != E.a)
return a < E.a;
return b > E.b;
}
};
class Pmd{
int T[N], D[N];
inline int tata(int x){
return T[x] == x ? x : T[x] = tata(T[x]);
}
public:
Pmd(){
for (int i = 1 ; i < N ; i++){
T[i] = i;
D[i] = 1;
}
}
inline bool merge(int x, int y){
x = tata(x);
y = tata(y);
if (x == y)
return false;
if (D[x] < D[y]){
D[y] += D[x];
T[x] = y;
} else {
D[x] += D[y];
T[y] = x;
}
return true;
}
};
Edge E[N];
Pmd P;
int main(){
ifstream in("lazy.in");
int n, nrE, x, y;
long long A, B;
in >> n >> nrE;
for (int i = 1 ; i <= nrE ; i++){
in >> x >> y >> A >> B;
E[i] = Edge(i, x, y, A, B);
}
in.close();
sort(E + 1, E + nrE + 1);
ofstream out("lazy.out");
for (int i = 1 ; i <= nrE ; i++)
if ( P.merge( E[i].x, E[i].y ) )
out << E[i].ind << '\n';
out.close();
return 0;
}