#include <bits/stdc++.h>
#define fast_cin ios_base::sync_with_stdio(0); cin.tie(NULL); cerr.tie(NULL);
#define endl "\n"
#define dbg(x) cerr << #x << ": " << x << endl;
#define DBG cerr << __LINE__ << ": I GOT STUCK\n";
using namespace std;
typedef long long ll;
typedef long double db;
const ll mxn = 1e5 + 10;
const ll INF = 1e8;
ll n,m,Q,k;
vector<ll>adj[mxn];
vector<ll>dist(mxn, INF);
ll sum(ll x){
return x * (x + 1)/2;
}
bool good(ll x, ll d){
return (k * sum(x) >= d);
}
ll find(ll d){
ll l = 0, r = 1e5+10;
ll ans = 0;
while(l <= r){
ll mid = l + (r - l)/2;
if(good(mid, d)){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
return ans;
}
void solve(){
cin >> n >> m >> Q >> k;
queue<ll>q;
for(ll i = 0;i<Q;i++){
ll x;cin >> x;
q.push(x);
dist[x] = 0;
}
for(ll i = 0;i<m;i++){
ll a, b;cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
while(!q.empty()){
ll node = q.front();
q.pop();
for(auto child: adj[node]){
if(dist[child] > dist[node] + 1){
dist[child] = dist[node] + 1;
q.push(child);
}
}
}
for(ll i = 1;i<=n;i++){
cout << find(dist[i]) << " \n"[i == n];
}
}
// 6 8 1 1
// 6
// 1 3
// 1 5
// 1 6
// 2 5
// 2 6
// 3 4
// 3 5
// 5 6
int main() {
fast_cin;
int test;test = 1;
// int test;cin >>test;
while(test--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3540 KB |
Output is correct |
2 |
Correct |
2 ms |
3464 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3460 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3460 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
4 |
Correct |
2 ms |
3464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
11676 KB |
Output is correct |
2 |
Correct |
109 ms |
12424 KB |
Output is correct |
3 |
Correct |
120 ms |
12880 KB |
Output is correct |
4 |
Correct |
92 ms |
10936 KB |
Output is correct |
5 |
Correct |
98 ms |
11204 KB |
Output is correct |
6 |
Correct |
104 ms |
12728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
12352 KB |
Output is correct |
2 |
Correct |
122 ms |
12232 KB |
Output is correct |
3 |
Correct |
113 ms |
12416 KB |
Output is correct |
4 |
Correct |
124 ms |
12644 KB |
Output is correct |
5 |
Correct |
103 ms |
12124 KB |
Output is correct |
6 |
Correct |
99 ms |
11660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
11852 KB |
Output is correct |
2 |
Correct |
108 ms |
12612 KB |
Output is correct |
3 |
Correct |
113 ms |
12748 KB |
Output is correct |
4 |
Correct |
116 ms |
12564 KB |
Output is correct |
5 |
Correct |
103 ms |
11656 KB |
Output is correct |
6 |
Correct |
88 ms |
11800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
11136 KB |
Output is correct |
2 |
Correct |
112 ms |
12100 KB |
Output is correct |
3 |
Correct |
103 ms |
12556 KB |
Output is correct |
4 |
Correct |
105 ms |
11784 KB |
Output is correct |
5 |
Correct |
87 ms |
11164 KB |
Output is correct |
6 |
Correct |
99 ms |
11688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
11268 KB |
Output is correct |
2 |
Correct |
97 ms |
11708 KB |
Output is correct |
3 |
Correct |
106 ms |
11712 KB |
Output is correct |
4 |
Correct |
99 ms |
11568 KB |
Output is correct |
5 |
Correct |
96 ms |
11716 KB |
Output is correct |
6 |
Correct |
89 ms |
11464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
11460 KB |
Output is correct |
2 |
Correct |
111 ms |
11828 KB |
Output is correct |
3 |
Correct |
91 ms |
11620 KB |
Output is correct |
4 |
Correct |
100 ms |
12068 KB |
Output is correct |
5 |
Correct |
98 ms |
11468 KB |
Output is correct |
6 |
Correct |
128 ms |
11836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
11492 KB |
Output is correct |
2 |
Correct |
85 ms |
11028 KB |
Output is correct |
3 |
Correct |
116 ms |
12688 KB |
Output is correct |
4 |
Correct |
107 ms |
11444 KB |
Output is correct |
5 |
Correct |
106 ms |
11840 KB |
Output is correct |
6 |
Correct |
109 ms |
12724 KB |
Output is correct |