#include <bits/stdc++.h>
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1e5+5;
int n,m,q,k;
vector<int> sec;
vector<vector<int> > adj;
vector<int> res;
vector<int> prec;
void bfs() {
queue<int> que;
vector<int> vis;
vis.resize(n+1);
for(auto i : sec) {
que.push(i);
vis[i] = 1;
}
que.push(-1);
int dist = 0;
while(que.size() > 1) {
int cur = que.front();
que.pop();
if(cur == -1) {
dist++;
que.push(-1);
continue;
}
//cout<<"cur:"<<cur<<"\n";
//cout<<"dist:"<<dist<<"\n";
res[cur] = prec[dist];
for(auto c : adj[cur]) {
if(vis[c]) continue;
que.push(c);
vis[c] = 1;
}
}
}
void solve() {
cin>>n>>m>>q>>k;
sec.resize(q);
res.resize(n+1);
adj.resize(n+1);
prec.resize(n+100);
int ind = 0;
int itr = 0;
while((ind-1) * (ind) * k / 2 < n+100) {
int x = ind * (ind+1) * k/2;
while(itr <= x && itr < n+100) {
prec[itr] = ind;
itr++;
}
ind++;
}
for(int i = 0; i<q; i++) {
cin>>sec[i];
}
for(int i = 0; i<m; i++) {
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
bfs();
for(int i = 1; i<=n; i++) {
cout<<res[i]<<" ";
}
}
signed main() {
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
8032 KB |
Output is correct |
2 |
Correct |
113 ms |
8276 KB |
Output is correct |
3 |
Correct |
121 ms |
8528 KB |
Output is correct |
4 |
Correct |
102 ms |
7820 KB |
Output is correct |
5 |
Correct |
105 ms |
7868 KB |
Output is correct |
6 |
Correct |
157 ms |
8480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
8296 KB |
Output is correct |
2 |
Correct |
106 ms |
8104 KB |
Output is correct |
3 |
Correct |
124 ms |
8204 KB |
Output is correct |
4 |
Correct |
128 ms |
8420 KB |
Output is correct |
5 |
Correct |
107 ms |
8020 KB |
Output is correct |
6 |
Correct |
104 ms |
8136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
8020 KB |
Output is correct |
2 |
Correct |
123 ms |
8532 KB |
Output is correct |
3 |
Correct |
125 ms |
8476 KB |
Output is correct |
4 |
Correct |
114 ms |
8272 KB |
Output is correct |
5 |
Correct |
100 ms |
8060 KB |
Output is correct |
6 |
Correct |
103 ms |
8228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
7760 KB |
Output is correct |
2 |
Correct |
110 ms |
8152 KB |
Output is correct |
3 |
Correct |
110 ms |
8392 KB |
Output is correct |
4 |
Correct |
109 ms |
8016 KB |
Output is correct |
5 |
Correct |
92 ms |
7716 KB |
Output is correct |
6 |
Correct |
114 ms |
8076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
7756 KB |
Output is correct |
2 |
Correct |
134 ms |
8128 KB |
Output is correct |
3 |
Correct |
105 ms |
8008 KB |
Output is correct |
4 |
Correct |
98 ms |
7836 KB |
Output is correct |
5 |
Correct |
100 ms |
7924 KB |
Output is correct |
6 |
Correct |
106 ms |
8364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
7964 KB |
Output is correct |
2 |
Correct |
107 ms |
8020 KB |
Output is correct |
3 |
Correct |
113 ms |
8120 KB |
Output is correct |
4 |
Correct |
106 ms |
8264 KB |
Output is correct |
5 |
Correct |
99 ms |
7924 KB |
Output is correct |
6 |
Correct |
113 ms |
8208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
8020 KB |
Output is correct |
2 |
Correct |
91 ms |
7872 KB |
Output is correct |
3 |
Correct |
115 ms |
8356 KB |
Output is correct |
4 |
Correct |
98 ms |
8040 KB |
Output is correct |
5 |
Correct |
117 ms |
8476 KB |
Output is correct |
6 |
Correct |
118 ms |
8652 KB |
Output is correct |