Submission
Status:
(PPPPPPPPP)(PPPP)(PPPPPP)(PPPPPPPPPP)
Subtask/Task Score:
{25/25}{25/25}{20/20}{30/30}
Score: 100
User: Fifaxmb
Problemset: เดินทางข้ามชุมชน
Language: cpp
Time: 0.166 second
Submitted On: 2026-04-12 14:09:47
#include<bits/stdc++.h>
using namespace std;
using ti3 = tuple<int,int,int>;
using ti4 = tuple<int,int,int,int>;
#define Fifa67king ios::sync_with_stdio(0);cin.tie(0);
using i64 = long long;
const int mxn = 2e5 + 5;
vector<int> head(mxn);
int find(int x){
if(head[x] == x) return x;
head[x] = find(head[x]);
return head[x];
}
bool chk(int u,int v){
u = find(u);
v = find(v);
if(u == v) return 0;
return 1;
}
int main(){
Fifa67king;
priority_queue<ti3,vector<ti3>,greater<ti3>> pq;
int n,m,q;cin >> n >> m >> q;;
// vector<ti3> p(m);
vector<vector<ti3>> adj(n + 1);
for(int i =0;i < m;i++){
int u,v,w;cin >> u >> v >> w;
pq.push({w,u,v});
}
vector<ti4> e(q);
for(int i = 0; i < q; i++){
int a,b,k;
cin >> a >> b >> k;
e[i] = {k,a,b,i};
}
// int j = 0;
vector<string> ans(q);
sort(e.begin(),e.end());
// sort(p.begin(),p.end());
for(int i = 1;i <= n;i++) head[i] = i;
for(auto[k,a,b,i] : e){
while(!pq.empty()){
auto[w,u,v] = pq.top();
if(w > k) break;
pq.pop();
if(chk(u,v)){
head[find(u)] = find(v);
}
}
if(find(a) == find(b)) ans[i] = "Yes";
else ans[i] = "No";
}
for(auto &s : ans) cout << s <<'\n';
// i64 sum = 0;
// while(!pq.empty()){
// auto[w,u,v] = pq.top();pq.pop();
// if(chk(u,v)){
// head[find_head(u)] = find_head(v);
// sum += w - 1;
// }
// }
// cout << sum;
}