Submission #1111367

#TimeUsernameProblemLanguageResultExecution timeMemory
1111367zhehanDrivers (BOI24_drivers)C++17
100 / 100
301 ms11968 KiB
#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 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...