結果
| 問題 |
No.3093 Safe Infection
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2025-04-06 15:57:01 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,844 bytes |
| コンパイル時間 | 3,545 ms |
| コンパイル使用メモリ | 293,644 KB |
| 実行使用メモリ | 30,776 KB |
| 最終ジャッジ日時 | 2025-04-06 15:57:17 |
| 合計ジャッジ時間 | 13,036 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 WA * 23 |
ソースコード
#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;
};
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));
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<N;i++){
for(auto[v,j]:G[i]){
if(abs(A[i].first-A[j].first)<=K)dsu.merge(i,j);
}
}
puts(dsu.count()==1?"Yes":"No");
}
Today03