Submission #433779

#TimeUsernameProblemLanguageResultExecution timeMemory
433779oscar1fBridges (APIO19_bridges)C++17
14 / 100
294 ms5392 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...