#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k, bcnt = 0;
cin >> n >> m >> k;
int a, b;
vector<pair<int, int>> edges;
for(int i = 1; i <= m; i++){
cin >> a >> b;
edges.emplace_back(a, b);
}
string s;
cin >> s;
vector<bool> isb(n + 1);
for(int i = 0; i < n; i++){
if(s[i] == '1'){
isb[i + 1] = 1;
bcnt++;
}
}
bcnt++;
vector<int> vec;
for(int i = 0; i < k; i++){
cin >> a;
vec.push_back(a);
}
vector<vector<vector<pair<int, int>>>> graph(n + 1, vector<vector<pair<int, int>>>(bcnt + 1));
for(auto &[x, y]: edges){
if(isb[x]){
for(int i = 0; i < bcnt; i++) graph[y][i].emplace_back(x, i + 1);
}
else{
for(int i = 0; i <= bcnt; i++) graph[y][i].emplace_back(x, i);
}
if(isb[y]){
for(int i = 0; i < bcnt; i++) graph[x][i].emplace_back(y, i + 1);
}
else{
for(int i = 0; i <= bcnt; i++) graph[x][i].emplace_back(y, i);
}
}
vector<vector<int>> dist(n + 1, vector<int>(bcnt + 1, 1e9));
queue<pair<int, int>> q;
for(int i = 1; i <= n; i++){
dist[i][(int)isb[i]] = 0;
q.emplace(i, (int)isb[i]);
}
while(!q.empty()){
auto [node, cnt] = q.front();
q.pop();
for(auto &[v, val]: graph[node][cnt]){
if(dist[v][val] == 1e9){
dist[v][val] = dist[node][cnt] + 1;
q.emplace(v, val);
}
}
}
vector<vector<int>> dist2(n + 1, vector<int>(bcnt + 1, 1e9));
dist2[vec[0]][0] = 0;
q.emplace(vec[0], 0);
while(!q.empty()){
auto [node, cnt] = q.front();
q.pop();
for(auto &[v, val]: graph[node][cnt]){
if(dist2[v][val] == 1e9){
dist2[v][val] = dist2[node][cnt] + 1;
q.emplace(v, val);
}
}
}
vector<ll> bans(bcnt + 1);
for(int i = 0; i < bcnt; i++){
for(int j = 1; j < k; j++){
if(isb[vec[j]]){
bans[i] += 1ll * dist[vec[j]][i + 1];
}
else{
bans[i] += 1ll * dist[vec[j]][i];
}
}
}
for(int i = 1; i <= n; i++){
ll ans = 1e18;
if(i == vec[0]){
cout << "0\n";
continue;
}
if(isb[i]){
for(int j = 1; j < bcnt; j++) ans = min(ans, bans[j - 1] + dist2[i][j]);
}
else{
for(int j = 0; j < bcnt; j++) ans = min(ans, bans[j] + dist2[i][j]);
}
cout << ans << "\n";
}
}
// g++ pA.cpp -std=c++17 -Wshadow -Wall -fsanitize=undefined -fsanitize=address -o run
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1368 KB |
Output is correct |
2 |
Correct |
19 ms |
9440 KB |
Output is correct |
3 |
Correct |
36 ms |
15572 KB |
Output is correct |
4 |
Correct |
35 ms |
15060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1368 KB |
Output is correct |
2 |
Correct |
26 ms |
10976 KB |
Output is correct |
3 |
Correct |
50 ms |
17620 KB |
Output is correct |
4 |
Correct |
49 ms |
17704 KB |
Output is correct |
5 |
Correct |
53 ms |
18128 KB |
Output is correct |
6 |
Correct |
49 ms |
17616 KB |
Output is correct |
7 |
Correct |
42 ms |
14800 KB |
Output is correct |
8 |
Correct |
44 ms |
16680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1624 KB |
Output is correct |
2 |
Correct |
38 ms |
13016 KB |
Output is correct |
3 |
Correct |
67 ms |
21128 KB |
Output is correct |
4 |
Correct |
73 ms |
20948 KB |
Output is correct |
5 |
Correct |
65 ms |
21440 KB |
Output is correct |
6 |
Correct |
66 ms |
20956 KB |
Output is correct |
7 |
Correct |
63 ms |
20948 KB |
Output is correct |
8 |
Correct |
71 ms |
21460 KB |
Output is correct |
9 |
Correct |
27 ms |
8912 KB |
Output is correct |
10 |
Correct |
25 ms |
8664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
201 ms |
67360 KB |
Output is correct |
3 |
Correct |
4 ms |
1628 KB |
Output is correct |
4 |
Correct |
512 ms |
162412 KB |
Output is correct |
5 |
Correct |
127 ms |
46768 KB |
Output is correct |
6 |
Correct |
12 ms |
5436 KB |
Output is correct |
7 |
Correct |
15 ms |
7004 KB |
Output is correct |
8 |
Correct |
1753 ms |
610852 KB |
Output is correct |
9 |
Correct |
458 ms |
125776 KB |
Output is correct |
10 |
Correct |
421 ms |
122196 KB |
Output is correct |
11 |
Correct |
328 ms |
102460 KB |
Output is correct |
12 |
Correct |
276 ms |
87124 KB |
Output is correct |
13 |
Correct |
145 ms |
46164 KB |
Output is correct |
14 |
Correct |
5 ms |
1540 KB |
Output is correct |
15 |
Correct |
19 ms |
10808 KB |
Output is correct |
16 |
Correct |
38 ms |
20052 KB |
Output is correct |
17 |
Correct |
126 ms |
48220 KB |
Output is correct |
18 |
Correct |
5 ms |
2652 KB |
Output is correct |
19 |
Correct |
5 ms |
2652 KB |
Output is correct |
20 |
Correct |
4 ms |
2652 KB |
Output is correct |
21 |
Correct |
1477 ms |
564752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
642 ms |
145872 KB |
Output is correct |
2 |
Runtime error |
391 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
642 ms |
145872 KB |
Output is correct |
2 |
Runtime error |
391 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
201 ms |
67360 KB |
Output is correct |
3 |
Correct |
4 ms |
1628 KB |
Output is correct |
4 |
Correct |
512 ms |
162412 KB |
Output is correct |
5 |
Correct |
127 ms |
46768 KB |
Output is correct |
6 |
Correct |
12 ms |
5436 KB |
Output is correct |
7 |
Correct |
15 ms |
7004 KB |
Output is correct |
8 |
Correct |
1753 ms |
610852 KB |
Output is correct |
9 |
Correct |
458 ms |
125776 KB |
Output is correct |
10 |
Correct |
421 ms |
122196 KB |
Output is correct |
11 |
Correct |
328 ms |
102460 KB |
Output is correct |
12 |
Correct |
276 ms |
87124 KB |
Output is correct |
13 |
Correct |
145 ms |
46164 KB |
Output is correct |
14 |
Correct |
5 ms |
1540 KB |
Output is correct |
15 |
Correct |
19 ms |
10808 KB |
Output is correct |
16 |
Correct |
38 ms |
20052 KB |
Output is correct |
17 |
Correct |
126 ms |
48220 KB |
Output is correct |
18 |
Correct |
5 ms |
2652 KB |
Output is correct |
19 |
Correct |
5 ms |
2652 KB |
Output is correct |
20 |
Correct |
4 ms |
2652 KB |
Output is correct |
21 |
Correct |
1477 ms |
564752 KB |
Output is correct |
22 |
Runtime error |
387 ms |
1048576 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1368 KB |
Output is correct |
2 |
Correct |
19 ms |
9440 KB |
Output is correct |
3 |
Correct |
36 ms |
15572 KB |
Output is correct |
4 |
Correct |
35 ms |
15060 KB |
Output is correct |
5 |
Correct |
3 ms |
1368 KB |
Output is correct |
6 |
Correct |
26 ms |
10976 KB |
Output is correct |
7 |
Correct |
50 ms |
17620 KB |
Output is correct |
8 |
Correct |
49 ms |
17704 KB |
Output is correct |
9 |
Correct |
53 ms |
18128 KB |
Output is correct |
10 |
Correct |
49 ms |
17616 KB |
Output is correct |
11 |
Correct |
42 ms |
14800 KB |
Output is correct |
12 |
Correct |
44 ms |
16680 KB |
Output is correct |
13 |
Correct |
3 ms |
1624 KB |
Output is correct |
14 |
Correct |
38 ms |
13016 KB |
Output is correct |
15 |
Correct |
67 ms |
21128 KB |
Output is correct |
16 |
Correct |
73 ms |
20948 KB |
Output is correct |
17 |
Correct |
65 ms |
21440 KB |
Output is correct |
18 |
Correct |
66 ms |
20956 KB |
Output is correct |
19 |
Correct |
63 ms |
20948 KB |
Output is correct |
20 |
Correct |
71 ms |
21460 KB |
Output is correct |
21 |
Correct |
27 ms |
8912 KB |
Output is correct |
22 |
Correct |
25 ms |
8664 KB |
Output is correct |
23 |
Correct |
5 ms |
2396 KB |
Output is correct |
24 |
Correct |
201 ms |
67360 KB |
Output is correct |
25 |
Correct |
4 ms |
1628 KB |
Output is correct |
26 |
Correct |
512 ms |
162412 KB |
Output is correct |
27 |
Correct |
127 ms |
46768 KB |
Output is correct |
28 |
Correct |
12 ms |
5436 KB |
Output is correct |
29 |
Correct |
15 ms |
7004 KB |
Output is correct |
30 |
Correct |
1753 ms |
610852 KB |
Output is correct |
31 |
Correct |
458 ms |
125776 KB |
Output is correct |
32 |
Correct |
421 ms |
122196 KB |
Output is correct |
33 |
Correct |
328 ms |
102460 KB |
Output is correct |
34 |
Correct |
276 ms |
87124 KB |
Output is correct |
35 |
Correct |
145 ms |
46164 KB |
Output is correct |
36 |
Correct |
5 ms |
1540 KB |
Output is correct |
37 |
Correct |
19 ms |
10808 KB |
Output is correct |
38 |
Correct |
38 ms |
20052 KB |
Output is correct |
39 |
Correct |
126 ms |
48220 KB |
Output is correct |
40 |
Correct |
5 ms |
2652 KB |
Output is correct |
41 |
Correct |
5 ms |
2652 KB |
Output is correct |
42 |
Correct |
4 ms |
2652 KB |
Output is correct |
43 |
Correct |
1477 ms |
564752 KB |
Output is correct |
44 |
Correct |
642 ms |
145872 KB |
Output is correct |
45 |
Runtime error |
391 ms |
1048576 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |