#include #define ALL(x) (x).begin(),(x).end() #define LB(v,x) (int)(lower_bound(ALL(v),x)-(v).begin()) #define UQ(v) sort(ALL(v)),(v).erase(unique(ALL(v)),(v).end()) #define IO ios::sync_with_stdio(false),cin.tie(nullptr); #define chmax(a,b)(a)=(a)<(b)?(b):(a) #define chmin(a,b)(a)=(a)<(b)?(a):(b) using namespace std; using ll=long long; const int INF=1e9+10; const ll INFL=4e18; struct DSU{ DSU()=default; DSU(int n){ par.resize(n); iota(par.begin(),par.end(),0); sz.assign(n,1); forest_count=n; } int find(int x){ if(par[x]==x)return x; return par[x]=find(par[x]); } bool merge(int x,int y){ x=find(x),y=find(y); if(x==y)return false; if(sz[x]>groups(){ int n=par.size(); vector>ret(n); for(int i=0;i&v){return v.empty();}),ret.end()); return ret; } private: vectorpar,sz; int forest_count; }; int main(){ ll N,M,K;cin>>N>>M>>K; vector>A(N); for(int i=0;i>A[i].first,A[i].second=i; vector>>G(N); for(int i=0;i>u>>v; u--,v--; G[u].insert({A[v].first,v}),G[v].insert({A[u].first,u}); } sort(ALL(A)); for(auto[v1,i]:A){ ll pv=v1; for(auto[v2,j]:G[i]){ if(abs(v1-v2)<=K)chmax(v1,v2); } A[i].first=v1; for(auto&[v2,j]:G[i]){ G[j].erase({pv,i}); G[j].insert({v1,i}); } } DSU dsu(N); for(int i=0;i