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>
#define mod 1000000007
#define inf 10000000000000000
using namespace std;
vector<vector<int> >mst , q;
pair<int , int>f[200000];
int erg[200000];
int fater(int x){
if(x == f[x].first){
return x;
}
f[x].first = fater(f[x].first);
return f[x].first;
}
void merge(int z , int x , int y){
while(q.size() && q[q.size() - 1][0] > z){
erg[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second;
q.pop_back();
}
if(fater(x) != fater(y)){
f[fater(x)].second += f[fater(y)].second;
f[fater(y)].first = fater(x);
}
}
int main(){
for(int i = 0 ; i < 200000 ; i++){
f[i] = {i , 1};
}
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int menge , numm , nummer , ed , cmp , comp ;;
cin >> menge >> ed;
for(int i = 0 ; i < ed ; i++){
cin >> numm >> nummer >> cmp;
mst.push_back({cmp , numm , nummer});
}
sort(mst.begin() , mst.end());
int que ;
cin >> que;
for(int i = 0 ; i < que ; i++){
cin >> cmp >> numm >> nummer;
q.push_back({nummer , numm , i});
}
sort(q.begin() , q.end());
for(int i = ed - 1; i >= 0 ; i--){
merge(mst[i][0] , mst[i][1] , mst[i][2]);
}
while(q.size() ){
erg[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second;
q.pop_back();
}
for(int i = 0 ; i < que ; i++){
cout << erg[i] << "\n";
}
}
Compilation message (stderr)
bridges.cpp: In function 'int main()':
bridges.cpp:31:43: warning: unused variable 'comp' [-Wunused-variable]
31 | int menge , numm , nummer , ed , cmp , comp ;;
| ^~~~
# | 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... |