## Submission #926324

# Submission time Handle Problem Language Result Execution time Memory
926324 2024-02-12T19:26:32 Z TAhmed33 Bridges (APIO19_bridges) C++
0 / 100
146 ms 4552 KB
```#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
int n, m;
struct DSU {
int sze[MAXN], par[MAXN];
void init (int n) {
for (int i = 1; i <= n; i++) {
sze[i] = 1; par[i] = i;
}
}
int find (int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
void merge (int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
if (sze[a] > sze[b]) swap(a, b);
sze[b] += sze[a]; par[a] = b;
}
} cur;
array <int, 3> p[MAXN];
int ans[MAXN];
int main () {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b, c; cin >> a >> b >> c; p[i] = {a, b, c};
}
sort(p + 1, p + m + 1, [] (array <int, 3> &x, array <int, 3> &y) {
return x[2] > y[2];
}); int ptr = 1;
int q; cin >> q;
vector <array <int, 3>> queries;
for (int i = 1; i <= q; i++) {
int a, b; cin >> a >> a >> b;
queries.push_back({b, a, i});
}
sort(queries.begin(), queries.end());
reverse(queries.begin(), queries.end());
cur.init(n);
for (auto i : queries) {
while (ptr <= m && p[ptr][2] >= i[2]) {
cur.merge(p[ptr][0], p[ptr][1]); ptr++;
}
ans[i[2]] = cur.sze[cur.find(i[1])];
}
for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}```

#### Subtask #1 0 / 13.0

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #2 0 / 16.0

# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 4392 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #3 0 / 17.0

# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 4552 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #4 0 / 14.0

# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 4392 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #5 0 / 13.0

# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 4392 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #6 0 / 27.0

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -