Submission
Status:
(PPPPPPPPP)(PPPP)(PPPPPP)(PPPPPPPPPP)
Subtask/Task Score:
{25/25}{25/25}{20/20}{30/30}
Score: 100
User: erng
Problemset: เดินทางข้ามชุมชน
Language: cpp
Time: 0.345 second
Submitted On: 2026-03-13 08:55:40
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5, qx=3e5+5;
int n, m, q, x, y, z, dsu[nx], ans[qx];
vector<tuple<int,int,int, int>> v;
int find(int x)
{
if (dsu[x]==x) return x;
else return dsu[x]=find(dsu[x]);
}
int main()
{
cin>>n>>m>>q;
for (int i=1; i<=n; i++) dsu[i]=i;
for (int i=1; i<=m; i++) cin>>x>>y>>z, v.push_back({z, 0, x, y});
for (int j=1; j<=q; j++) cin>>x>>y>>z, v.push_back({z, j, x, y});
sort(v.begin(), v.end());
for (int i=0; i<v.size(); i++)
{
auto [w, idx, u, k]=v[i];
if (!idx) dsu[find(u)]=find(k);
else if (find(u)==find(k)) ans[idx]=1;
}
for (int i=1; i<=q; i++)
{
if (ans[i]) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
}
}