Submission #238617

# Submission time Handle Problem Language Result Execution time Memory
238617 2020-06-12T07:58:01 Z SamAnd Birmingham (COCI20_birmingham) C++17
70 / 70
153 ms 10748 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;

int n, m, q, k;
vector<int> g[N];

int ans[N];

bool c[N];
int dist[N];

void solv()
{
    scanf("%d%d%d%d", &n, &m, &q, &k);
    for (int i = 1; i <= n; ++i)
        ans[i] = -1;
    while (q--)
    {
        int x;
        scanf("%d", &x);
        ans[x] = 0;
    }
    while (m--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int d = 1; ; ++d)
    {
        bool z = true;
        for (int i = 1; i <= n; ++i)
        {
            if (ans[i] == -1)
            {
                z = false;
                break;
            }
        }
        if (z)
            break;
        queue<int> q;
        for (int i = 1; i <= n; ++i)
        {
            c[i] = false;
            if (ans[i] != -1)
            {
                c[i] = true;
                dist[i] = 0;
                q.push(i);
            }
        }
        while (!q.empty())
        {
            int x = q.front();
            q.pop();
            if (dist[x] > d * k)
                continue;
            if (ans[x] == -1)
                ans[x] = d;
            for (int i = 0; i < g[x].size(); ++i)
            {
                int h = g[x][i];
                if (!c[h])
                {
                    c[h] = true;
                    dist[h] = dist[x] + 1;
                    q.push(h);
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", ans[i]);
    printf("\n");
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

birmingham.cpp: In function 'void solv()':
birmingham.cpp:71:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < g[x].size(); ++i)
                             ~~^~~~~~~~~~~~~
birmingham.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &n, &m, &q, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
birmingham.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
birmingham.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 7 ms 2688 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 7 ms 2688 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 111 ms 9824 KB Output is correct
2 Correct 119 ms 10448 KB Output is correct
3 Correct 127 ms 10748 KB Output is correct
4 Correct 98 ms 9416 KB Output is correct
5 Correct 105 ms 9576 KB Output is correct
6 Correct 123 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 10320 KB Output is correct
2 Correct 126 ms 10196 KB Output is correct
3 Correct 123 ms 10436 KB Output is correct
4 Correct 121 ms 10444 KB Output is correct
5 Correct 115 ms 10196 KB Output is correct
6 Correct 99 ms 9896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 9944 KB Output is correct
2 Correct 123 ms 10444 KB Output is correct
3 Correct 129 ms 10636 KB Output is correct
4 Correct 122 ms 10480 KB Output is correct
5 Correct 103 ms 9776 KB Output is correct
6 Correct 103 ms 9908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 9704 KB Output is correct
2 Correct 124 ms 10228 KB Output is correct
3 Correct 120 ms 10440 KB Output is correct
4 Correct 108 ms 9820 KB Output is correct
5 Correct 120 ms 9568 KB Output is correct
6 Correct 107 ms 9884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 9572 KB Output is correct
2 Correct 142 ms 9948 KB Output is correct
3 Correct 115 ms 9968 KB Output is correct
4 Correct 111 ms 9952 KB Output is correct
5 Correct 109 ms 9824 KB Output is correct
6 Correct 101 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 9580 KB Output is correct
2 Correct 121 ms 10072 KB Output is correct
3 Correct 112 ms 9864 KB Output is correct
4 Correct 116 ms 10184 KB Output is correct
5 Correct 103 ms 9824 KB Output is correct
6 Correct 113 ms 10040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 9824 KB Output is correct
2 Correct 117 ms 9468 KB Output is correct
3 Correct 153 ms 10652 KB Output is correct
4 Correct 116 ms 9700 KB Output is correct
5 Correct 111 ms 10072 KB Output is correct
6 Correct 126 ms 10544 KB Output is correct