Cod sursa(job #2579158)
Utilizator | Data | 12 martie 2020 00:31:40 | |
---|---|---|---|
Problema | Lazy | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 4.11 kb |
/**
~~- __.--~~ _/ | \
~~~ /\ \_ -._ \
--.__ __.--~~ __.-----~ ~-._ ~-._~~-. |
___ ~~ _.-~ ~~-._ ~\ \
~~~~---.___.---~_.- ~-._ \ |
_.-~ --~/ / ~~\ |'
/ .-~~~~-./ // / ,;;;;;;;,, /| )'
/ / ~~-. \ / / ``';;;;;, ~/ '
| | \ ; | / `';;;, |~
| | _| (((( '; | .-~
| | /~ | `~~--.___/ |,..| (_
| | | ``` /,;;;| ( ~-
| | / | _ / __.--\ \
\ \__ \ |~ .-~~ ~- )
- \ | /.,.. \
/ `---' , . | _/ ;;;;;,
/ | ; ___.---~~ `'';;;
| \__.--._ __.-~~ _| `';.
| '~~~.-~~ _/ ~\ `';.
| , ( `;;\ `. `;,
| _.-~~~~~~-.|\ -. . `:;\ | `;
| __~~__.---._ _/ `\ `\ | `'`,.|
| \ ~~--._)..--~ _.-'.' ,' `
\ \ - _\ /`. ~-~ _.-'
`\ `._ .' ( | / (
`\ ~--~ _.-\ | ((_(
`\ / .~ ( || ) \)
/ `._ | \_ `\; |
/' ~--.____.-~ / ~~~~~ /--/ / |
/ / ._((_/| /
/ | _()_/(
| | \ / |
\_ `. _.-~ \/ /
~-._ ~-._ _______________.-~ / ) /( |
~-._ ~~--._ | | )
~-.__ ~-._ | /| /)
~~--.__ \ \ \| |
~-._ | ))| |
~\ | ( \ \ )
`\ | | |(
\ | )) )
( ((
**/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <random>
using namespace std;
typedef long long ll;
mt19937 rng((long long) (new char));
const int N = 200000 + 7;
int n;
int m;
int a[N];
int b[N];
ll c1[N];
ll c2[N];
int t[N];
int ord[N];
bool cmp(int i, int j) {
if (c1[i] != c1[j]) {
return c1[i] < c1[j];
} else {
return c2[i] > c2[j];
}
}
int get(int a) {
while (a != t[a]) {
a = t[a];
}
return a;
}
void unite(int a, int b) {
if (rng() & 1) {
swap(a, b);
}
t[a] = b;
}
int main() {
freopen ("lazy.in", "r", stdin);
freopen ("lazy.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
t[i] = i;
}
for (int i = 1; i <= m; i++) {
scanf("%d %d %lld %lld", &a[i], &b[i], &c1[i], &c2[i]);
ord[i] = i;
}
sort(ord + 1, ord + m + 1, cmp);
for (int j = 1; j <= m; j++) {
int i = ord[j];
int x = get(a[i]);
int y = get(b[i]);
if (x != y) {
printf("%d\n", i);
unite(x, y);
}
}
}