結果
問題 |
No.3093 Safe Infection
|
ユーザー |
![]() |
提出日時 | 2025-04-06 16:13:46 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,935 bytes |
コンパイル時間 | 3,530 ms |
コンパイル使用メモリ | 296,368 KB |
実行使用メモリ | 814,592 KB |
最終ジャッジ日時 | 2025-04-06 16:13:57 |
合計ジャッジ時間 | 10,835 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 42 MLE * 1 -- * 27 |
ソースコード
#include<bits/stdc++.h> #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]<sz[y])swap(x,y); par[y]=x; sz[x]+=sz[y]; forest_count--; return true; } int size(int x){return sz[find(x)];} bool same(int x,int y){return find(x)==find(y);} int count(){return forest_count;} vector<vector<int>>groups(){ int n=par.size(); vector<vector<int>>ret(n); for(int i=0;i<n;i++)ret[find(i)].push_back(i); ret.erase(remove_if(ret.begin(),ret.end(),[&](const vector<int>&v){return v.empty();}),ret.end()); return ret; } private: vector<int>par,sz; int forest_count; }; /* 操作をする→頂点を縮約できる 最終的に1つの頂点にできるか? */ int main(){ ll N,M,K;cin>>N>>M>>K; vector<pair<ll,ll>>A(N); for(int i=0;i<N;i++)cin>>A[i].first,A[i].second=i; vector<set<pair<ll,ll>>>G(N); for(int i=0;i<M;i++){ int u,v;cin>>u>>v,u--,v--; G[u].insert({A[v].first,v}); G[v].insert({A[u].first,u}); } sort(ALL(A)); vector<bool>seen(N,false); DSU dsu(N); for(auto a:A){ auto[v,i]=a; auto itr=G[i].lower_bound({v,-1}); if(itr==G[i].end())continue; auto[v2,i2]=*itr; if(abs(v2-v)>K)continue; dsu.merge(i,i2); for(auto p:G[i])G[p.second].erase(a); for(auto p:G[i])if(p.second!=i2)G[i2].insert(p); } puts(dsu.count()==1?"Yes":"No"); }