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