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;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<iii,int> iiii;
int ufds[200000];
int f(int a){
if(ufds[a]==a){
return a;
}
return ufds[a]=f(ufds[a]);
}
void join(int a,int b){
ufds[f(a)]=f(b);
}
int main()
{
int n,m,u,a,b,c;
cin>>n>>m>>u;
for(int i=0;i<=n;++i){
ufds[i]=i;
}
priority_queue<iii,vector<iii>,greater<iii>>roads;
for(int i=0;i<m;++i){
cin>>a>>b>>c;
roads.push(iii(c,ii(a,b)));
}
priority_queue<iiii,vector<iiii>,greater<iiii>> qrys;
for(int i=0;i<u;++i){
cin>>a>>b>>c;
qrys.push(iiii(iii(c,ii(a,b)),i));
}
bool arr[u];
while(!qrys.empty()){
iiii qry=qrys.top();
qrys.pop();
int p=qry.first.first;
int a=qry.first.second.first;
int b=qry.first.second.second;
while(!roads.empty()&&roads.top().first<=p){
iii r=roads.top();
int ca=r.second.first;
int cb=r.second.second;
join(ca,cb);
roads.pop();
}
arr[qry.second]=f(a)==f(b);
}
for(int i=0;i<u;++i){
if(arr[i]){
cout<<"TAIP"<<'\n';
}else{
cout<<"NE"<<'\n';
}
}
return 0;
}
# | 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... |