| 比赛 |
2026.3.28 |
评测结果 |
AAWAAAAAAWWWWWWWWWWWWWW |
| 题目名称 |
Picking Flowers |
最终得分 |
32 |
| 用户昵称 |
汐汐很希希 |
运行时间 |
16.960 s |
| 代码语言 |
C++ |
内存使用 |
26.26 MiB |
| 提交时间 |
2026-03-28 10:18:10 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int N=2e5+10;
const int M=2e5+10;
int n,m,k,l,s[N],d[N],vis[N],lis[N];
vector<int> prv[N];
vector<int> g[N];
void init(){
for(int i=1;i<=n;i++) g[i].clear();
}
priority_queue<pair<int,int> ,vector<pair<int,int> >,greater<pair<int,int> > > pq;
void dij()
{
int s=1;
memset(lis,0x3f,sizeof(lis));
lis[s]=0;
pq.push({0,s});
while(!pq.empty())
{
pair<int,int> t=pq.top();
pq.pop();
int d=t.first,u=t.second;
if(d!=lis[u]) continue;
for(int i=0;i<g[u].size();i++){
int v=g[u][i],nd=d+1;
if(nd<lis[v]){
lis[v]=nd;
prv[v].clear();
prv[v].push_back(u);
pq.push({nd,v});
}else if(nd==lis[v]){
prv[v].push_back(u);
}
}
}
}
void getPath(int x)
{
if(x==1) return;
else{
vis[x]=true;
queue<int> q;
q.push(x);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=0;i<prv[u].size();i++){
int v=prv[u][i];
if(!vis[v]){
vis[v]=true;
q.push(v);
}
}
}
return;
}
}
int main()
{
freopen("Flowers.in","r",stdin);
freopen("Flowers.out","w",stdout);
int T;
cin>>T;
while(T--)
{
init();
cin>>n>>m>>k>>l;
for(int i=1;i<=k;i++) cin>>s[i];
for(int i=1;i<=l;i++) cin>>d[i];
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
dij();
if(k==0){
memset(vis,0,sizeof(vis));
vis[1]=true;
for(int i=1;i<=l;i++) getPath(d[i]);
for(int i=2;i<=n;i++){
if(vis[i]) cout<<1;
else cout<<0;
}
}
cout<<endl;
}
return 0;
}