#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
int n, m, Q, k;
int dist[100005];
vi g[100005];
ll go(int d){
ll l = 0, r = 1e5;
while(l < r){
ll mid = (l + r) / 2;
if((k * ((mid * (mid + 1)) / 2)) >= d) r = mid;
else l = mid + 1;
}
return l;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
cin >> n >> m >> Q >> k;
set<pi> q;
rep(i, 100005) dist[i] = 1e9;
rep(i, Q){
int x;
cin >> x;
x--;
dist[x] = 0;
q.insert(mp(x, dist[x]));
}
rep(i, m){
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
while(!q.empty()){
int u = q.begin() -> fi;
q.erase(q.begin());
for(int x : g[u]){
if((dist[u] + 1) < dist[x]){
q.erase(mp(x, dist[x]));
dist[x] = dist[u] + 1;
q.insert(mp(x, dist[x]));
}
}
}
rep(i, n){
cout << go(dist[i]) << " ";
}
cout << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
8 ms |
3072 KB |
Output is correct |
3 |
Correct |
6 ms |
3092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
3 |
Correct |
7 ms |
3072 KB |
Output is correct |
4 |
Correct |
7 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
4 |
Correct |
7 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
7 ms |
3072 KB |
Output is correct |
3 |
Correct |
7 ms |
3072 KB |
Output is correct |
4 |
Correct |
6 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
358 ms |
11640 KB |
Output is correct |
2 |
Correct |
384 ms |
12280 KB |
Output is correct |
3 |
Correct |
189 ms |
13048 KB |
Output is correct |
4 |
Correct |
278 ms |
11000 KB |
Output is correct |
5 |
Correct |
355 ms |
11264 KB |
Output is correct |
6 |
Correct |
148 ms |
13560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
280 ms |
12152 KB |
Output is correct |
2 |
Correct |
319 ms |
12008 KB |
Output is correct |
3 |
Correct |
166 ms |
12408 KB |
Output is correct |
4 |
Correct |
367 ms |
12280 KB |
Output is correct |
5 |
Correct |
318 ms |
12024 KB |
Output is correct |
6 |
Correct |
133 ms |
13048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
11768 KB |
Output is correct |
2 |
Correct |
326 ms |
12280 KB |
Output is correct |
3 |
Correct |
177 ms |
12920 KB |
Output is correct |
4 |
Correct |
362 ms |
12280 KB |
Output is correct |
5 |
Correct |
264 ms |
11512 KB |
Output is correct |
6 |
Correct |
132 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
284 ms |
11256 KB |
Output is correct |
2 |
Correct |
306 ms |
12024 KB |
Output is correct |
3 |
Correct |
166 ms |
12536 KB |
Output is correct |
4 |
Correct |
268 ms |
11512 KB |
Output is correct |
5 |
Correct |
263 ms |
11164 KB |
Output is correct |
6 |
Correct |
132 ms |
12792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
11256 KB |
Output is correct |
2 |
Correct |
286 ms |
11640 KB |
Output is correct |
3 |
Correct |
154 ms |
11896 KB |
Output is correct |
4 |
Correct |
353 ms |
11640 KB |
Output is correct |
5 |
Correct |
317 ms |
11512 KB |
Output is correct |
6 |
Correct |
133 ms |
12744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
280 ms |
11332 KB |
Output is correct |
2 |
Correct |
303 ms |
11640 KB |
Output is correct |
3 |
Correct |
147 ms |
12152 KB |
Output is correct |
4 |
Correct |
357 ms |
12024 KB |
Output is correct |
5 |
Correct |
288 ms |
11384 KB |
Output is correct |
6 |
Correct |
134 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
11512 KB |
Output is correct |
2 |
Correct |
283 ms |
11000 KB |
Output is correct |
3 |
Correct |
202 ms |
12792 KB |
Output is correct |
4 |
Correct |
275 ms |
11384 KB |
Output is correct |
5 |
Correct |
291 ms |
11844 KB |
Output is correct |
6 |
Correct |
142 ms |
13560 KB |
Output is correct |