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<bits/stdc++.h>
using namespace std;
const int MAX_SOMMET=50*1000+1;
int nbIles,nbPonts,deb,fin,poids,nbReq,typeReq;
tuple<int,int,int> pos;
vector<tuple<int,int,int>> req;
vector<pair<int,int>> reponse;
int pere[MAX_SOMMET],prof[MAX_SOMMET];
int find(int pers) {
if (pere[pers]!=pers) {
pere[pers]=find(pere[pers]);
}
return pere[pers];
}
int main() {
ios_base::sync_with_stdio(false);
cin>>nbIles>>nbPonts;
for (int i=1;i<=nbPonts;i++) {
cin>>deb>>fin>>poids;
req.push_back(make_tuple(poids,deb,fin));
}
cin>>nbReq;
for (int ireq=1;ireq<=nbReq;ireq++) {
cin>>typeReq>>deb>>poids;
req.push_back(make_tuple(poids,-deb,ireq));
}
sort(req.begin(),req.end());
for (int i=1;i<=nbIles;i++) {
pere[i]=i;
prof[i]=1;
}
while (req.size()>0) {
pos=req.back();
req.pop_back();
//cout<<get<0>(pos)<<" "<<get<1>(pos)<<" "<<get<2>(pos)<<" ";
if (get<1>(pos)>0) {
deb=find(get<1>(pos));
fin=find(get<2>(pos));
if (deb!=fin) {
pere[fin]=deb;
prof[deb]+=prof[fin];
}
//cout<<prof[1]<<" "<<prof[2]<<" "<<prof[3]<<endl;
}
else {
reponse.push_back(make_pair(get<2>(pos),prof[find(-get<1>(pos))]));
//cout<<reponse.back().second<<" "<<find(-get<1>(pos))<<endl;
}
}
sort(reponse.begin(),reponse.end());
for (int i=0;i<nbReq;i++) {
cout<<reponse[i].second<<endl;
}
}
# | 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... |