卬高杯
提出id | 提出時刻 | ユーザー名 | 問題 | 言語 | 判定状況 | 判定 | 実行時間 |
---|---|---|---|---|---|---|---|
114869 | 2023-10-24 09:25:28 | n_o_n_o_n | J | cpp | 11/11 | WA | 27 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll N,M,X,P,B[100],T[1<<17];
vector<ll> G[1<<17];
bool check[1<<17],vis[1<<17];
int main(){
cin>>N>>M>>X>>P;
for(int i=0; i<N; i++)cin>>B[i];
for(int j=0; j<M; j++)
{
cin>>T[j];
for(int i=0; i<N; i++)
{
if(abs(T[j]-B[i])<=P)check[j]=1;
}
}
for(;X--;)
{
ll u,v;
cin>>u>>v;
u--,v--;
G[u].push_back(v);
G[v].push_back(u);
}
ll ans=0;
for(ll i=0; i<N; i++)if(check[i]&&!vis[i])
{
ans++;
vis[i]=1;
queue<ll>q;
q.push(i);
while(!q.empty())
{
ll u=q.front();
q.pop();
for(ll v:G[u])
{
if(vis[v])continue;
vis[v]=1;
q.push(v);
}
}
}
cout << ans << endl;
}
case1.txt AC 8 case2.txt WA 11 case3.txt WA 14 case4.txt WA 13 case5.txt WA 24 case6.txt WA 25 case9.txt WA 25 case10.txt WA 25 case11.txt WA 27 case13.txt WA 14 sample1.txt AC 14 27 WA27 WA