답안 #238460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238460 2020-06-11T12:14:01 Z dimitar_ne Birmingham (COCI20_birmingham) C++14
70 / 70
157 ms 7928 KB
#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 100003
using namespace std;
int n, m, t, k;
vector <int> adj[MAXN];
int dist[MAXN];
queue <int> q;

void input()
{
    cin >> n >> m >> t >> k;

    for (int i = 0; i <= n; ++i)
        dist[i] = -1;

    for (int i = 0; i < t; ++i)
    {
        int x;
        cin >> x;
        dist[x] = 0;
        q.push(x);
    }

    for (int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void bfs()
{
    while (!q.empty())
    {
        int tmp = q.front();
        q.pop();

        for (auto nb: adj[tmp])
        {
            if (dist[nb] == -1 || dist[nb] > dist[tmp] + 1)
            {
                dist[nb] = dist[tmp] + 1;
                q.push(nb);
            }
        }
    }
}

int get_ans(int x)
{
    if (x == 0)
        return 0;
    if (x <= k)
        return 1;

    int d = k;

    for (int i = 2; ; ++i)
    {
        d += i * k;
        if (d >= x)
            return i;
    }
}

void solve()
{
    bfs();
    
    cout << get_ans(dist[1]);
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << get_ans(dist[i]);// << dist[i] << endl;
    }

    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    input();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 7 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 7416 KB Output is correct
2 Correct 112 ms 7672 KB Output is correct
3 Correct 117 ms 7928 KB Output is correct
4 Correct 103 ms 7160 KB Output is correct
5 Correct 94 ms 7288 KB Output is correct
6 Correct 100 ms 7800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 7672 KB Output is correct
2 Correct 97 ms 7672 KB Output is correct
3 Correct 106 ms 7672 KB Output is correct
4 Correct 140 ms 7928 KB Output is correct
5 Correct 95 ms 7672 KB Output is correct
6 Correct 89 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 7544 KB Output is correct
2 Correct 108 ms 7928 KB Output is correct
3 Correct 103 ms 7800 KB Output is correct
4 Correct 102 ms 7800 KB Output is correct
5 Correct 86 ms 7416 KB Output is correct
6 Correct 119 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 7288 KB Output is correct
2 Correct 103 ms 7544 KB Output is correct
3 Correct 101 ms 7672 KB Output is correct
4 Correct 132 ms 7520 KB Output is correct
5 Correct 85 ms 7288 KB Output is correct
6 Correct 86 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 7288 KB Output is correct
2 Correct 88 ms 7544 KB Output is correct
3 Correct 90 ms 7416 KB Output is correct
4 Correct 90 ms 7416 KB Output is correct
5 Correct 90 ms 7416 KB Output is correct
6 Correct 87 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 7288 KB Output is correct
2 Correct 90 ms 7544 KB Output is correct
3 Correct 89 ms 7420 KB Output is correct
4 Correct 93 ms 7636 KB Output is correct
5 Correct 91 ms 7416 KB Output is correct
6 Correct 89 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 7544 KB Output is correct
2 Correct 83 ms 7160 KB Output is correct
3 Correct 157 ms 7800 KB Output is correct
4 Correct 84 ms 7416 KB Output is correct
5 Correct 104 ms 7584 KB Output is correct
6 Correct 152 ms 7800 KB Output is correct