# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
433827 | JeanBombeur | Bridges (APIO19_bridges) | C++17 | 107 ms | 3660 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
// <|°_°|>
const int MAX_NOEUDS = (100 * 1000);
struct arete {
int dep, fin, poids;
};
arete Aretes[2 * MAX_NOEUDS];
arete Requetes[MAX_NOEUDS];
int Ans[MAX_NOEUDS];
int Dsu[MAX_NOEUDS];
int nbNoeuds, nbAretes, nbRequetes;
bool operator<(arete a, arete b) {
return a.poids > b.poids;
}
int Find(int a) {
if (Dsu[a] < 0)
return a;
return Dsu[a] = Find(Dsu[a]);
}
void Union(int id) {
int ra = Find(Aretes[id].dep), rb = Find(Aretes[id].fin);
if (ra == rb)
return;
if (Dsu[ra] > Dsu[rb])
swap(ra, rb);
Dsu[ra] += Dsu[rb];
Dsu[rb] = ra;
return;
}
void Read() {
scanf("%d %d", &nbNoeuds, &nbAretes);
fill_n(Dsu, nbNoeuds, -1);
for (int i = 0; i < nbAretes; i ++)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
Aretes[i] = {-- a, -- b, c};
}
sort(Aretes, Aretes + nbAretes);
return;
}
void Solve() {
scanf("%d", &nbRequetes);
for (int i = 0; i < nbRequetes; i ++)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
Requetes[i] = {-- b, i, c};
}
sort(Requetes, Requetes + nbRequetes);
int curArete = 0;
for (int i = 0; i < nbRequetes; i ++)
{
while (curArete < nbAretes && Aretes[curArete].poids >= Requetes[i].poids)
Union(curArete ++);
Ans[Requetes[i].fin] = - Dsu[Find(Requetes[i].dep)];
}
for (int i = 0; i < nbRequetes; i ++)
{
printf("%d\n", Ans[i]);
}
return;
}
int main() {
Read();
Solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |