#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int int64_t
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define F first
#define S second
#define I insert
#define PB push_back
#define POB pop_back
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
#define tm ((l) + (r)) / 2
int binpow(int a, int p, int m = MOD) {
int ans = 1;
while (p) {
if (p & 1) ans = ((ans % m) * (a % m)) % m;
a = sqr(a) % m;
p >>= 1;
}
return ans;
}
int n, m, q, k;
vector<int> meet, dist;
vector<vector<int>> adj;
vector<bool> vis;
void bfs(int s = 0) {
vis[s] = true;
queue<int> q;
q.push(s);
dist[s] = -1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto x : adj[u]) {
if (vis[x]) continue;
vis[x] = true;
dist[x] = dist[u] + 1;
q.push(x);
}
}
}
int f(int a) { return ((a * (a + 1)) / 2) * k; }
void solve() {
cin >> n >> m >> q >> k;
for (int i = 0; i < q; i++) {
int tmp;
cin >> tmp;
meet.PB(tmp);
}
adj.assign(n + 1, {});
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].PB(b);
adj[b].PB(a);
}
for (int i = 0; i < q; i++) {
adj[0].PB(meet[i]);
adj[meet[i]].PB(0);
}
dist.assign(n + 1, 0);
vis.assign(n + 1, false);
bfs();
for (int i = 1; i <= n; i++) {
int l = 0, r = dist[i];
while (r - l > 1) {
if (f(tm) >= dist[i])
r = tm;
else
l = tm + 1;
}
if (f(l) >= dist[i])
cout << l << ' ';
else
cout << r << ' ';
}
}
int32_t main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
9812 KB |
Output is correct |
2 |
Correct |
121 ms |
10320 KB |
Output is correct |
3 |
Correct |
139 ms |
11976 KB |
Output is correct |
4 |
Correct |
91 ms |
9296 KB |
Output is correct |
5 |
Correct |
98 ms |
9348 KB |
Output is correct |
6 |
Correct |
129 ms |
12628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
10192 KB |
Output is correct |
2 |
Correct |
111 ms |
10068 KB |
Output is correct |
3 |
Correct |
131 ms |
11084 KB |
Output is correct |
4 |
Correct |
141 ms |
10320 KB |
Output is correct |
5 |
Correct |
132 ms |
10296 KB |
Output is correct |
6 |
Correct |
129 ms |
11976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
10000 KB |
Output is correct |
2 |
Correct |
126 ms |
10296 KB |
Output is correct |
3 |
Correct |
137 ms |
11560 KB |
Output is correct |
4 |
Correct |
120 ms |
10320 KB |
Output is correct |
5 |
Correct |
108 ms |
9552 KB |
Output is correct |
6 |
Correct |
132 ms |
11976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
9296 KB |
Output is correct |
2 |
Correct |
159 ms |
10048 KB |
Output is correct |
3 |
Correct |
134 ms |
11212 KB |
Output is correct |
4 |
Correct |
122 ms |
9680 KB |
Output is correct |
5 |
Correct |
128 ms |
9300 KB |
Output is correct |
6 |
Correct |
129 ms |
11720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
9536 KB |
Output is correct |
2 |
Correct |
139 ms |
9812 KB |
Output is correct |
3 |
Correct |
109 ms |
10608 KB |
Output is correct |
4 |
Correct |
104 ms |
9556 KB |
Output is correct |
5 |
Correct |
105 ms |
9848 KB |
Output is correct |
6 |
Correct |
111 ms |
11712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
9556 KB |
Output is correct |
2 |
Correct |
106 ms |
9808 KB |
Output is correct |
3 |
Correct |
108 ms |
10952 KB |
Output is correct |
4 |
Correct |
112 ms |
10064 KB |
Output is correct |
5 |
Correct |
104 ms |
9552 KB |
Output is correct |
6 |
Correct |
119 ms |
11972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
9792 KB |
Output is correct |
2 |
Correct |
98 ms |
9296 KB |
Output is correct |
3 |
Correct |
126 ms |
11464 KB |
Output is correct |
4 |
Correct |
100 ms |
9620 KB |
Output is correct |
5 |
Correct |
111 ms |
9764 KB |
Output is correct |
6 |
Correct |
147 ms |
12428 KB |
Output is correct |