답안 #993693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993693 2024-06-06T10:11:33 Z danikoynov Wells (CEOI21_wells) C++14
0 / 100
5 ms 1628 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e4 + 10;

int n, k;
vector < int > adj[maxn];

int dist[maxn];
void bfs(int v)
{
    for (int i = 1; i <= n; i ++)
        dist[i] = -1;

    queue < int > q;
    q.push(v);
    dist[v] = 0;
    while(!q.empty())
    {
        v = q.front();
        q.pop();
        for (int u : adj[v])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}

int forb[maxn], path[maxn][maxn];
void bfs_forb(int v)
{
        for (int i = 1; i <= n; i ++)
        dist[i] = -1;

    queue < int > q;
    q.push(v);
    dist[v] = 0;
    while(!q.empty())
    {
        v = q.front();
        q.pop();
        for (int u : adj[v])
        {
            if (forb[u] == 0 && dist[u] == -1)
            {
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}
void solve()
{
    cin >> n >> k;
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }

    for (int i = 1; i <= n; i ++)
    {
        bfs(i);
        for (int j = 1; j <= n; j ++)
            path[i][j] = dist[j];
    }

    for (int s = 1; s <= n; s ++)
    {
        bfs(s);
        vector < int > st;
        for (int i = 1; i <= n; i ++)
            forb[i] = 0;
        for (int i = 1; i <= n; i ++)
        {
            if (dist[i] % k == 0)
            {
                forb[i] = 1;
                st.push_back(i);
            }
        }


        bool fine = true;
        for (int i = 0; i < st.size(); i ++)
            for (int j = i + 1; j < st.size(); j ++)
        {
            if (path[st[i]][st[j]] < k)
            {
                fine = false;
            }
        }

        if (!fine)
            continue;

        for (int i = 1; i <= n; i ++)
        {
            if (forb[i])
                continue;

            bfs_forb(i);
            ///cout << "start " << i << endl;
            for (int j = 1; j <= n; j ++)
                if (dist[j] + 1 >= k)
            {
                fine = false;
            }
        }

        if (fine)
        {
            cout << "YES" << endl;
            cout << 0 << endl;
            return;
        }
    }

    cout << "NO" << endl;
    cout << 0 << endl;
}

int main()
{
    speed();
    solve();
    return 0;
}

Compilation message

wells.cpp: In function 'void solve()':
wells.cpp:101:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for (int i = 0; i < st.size(); i ++)
      |                         ~~^~~~~~~~~~~
wells.cpp:102:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             for (int j = i + 1; j < st.size(); j ++)
      |                                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 600 KB Output is partially correct
2 Partially correct 2 ms 1628 KB Output is partially correct
3 Partially correct 1 ms 1628 KB Output is partially correct
4 Partially correct 1 ms 1628 KB Output is partially correct
5 Partially correct 2 ms 1628 KB Output is partially correct
6 Partially correct 1 ms 1628 KB Output is partially correct
7 Correct 2 ms 1628 KB Output is correct
8 Partially correct 1 ms 1628 KB Output is partially correct
9 Partially correct 2 ms 1624 KB Output is partially correct
10 Correct 5 ms 1628 KB Output is correct
11 Incorrect 2 ms 1628 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 600 KB Output is partially correct
2 Partially correct 2 ms 1628 KB Output is partially correct
3 Partially correct 1 ms 1628 KB Output is partially correct
4 Partially correct 1 ms 1628 KB Output is partially correct
5 Partially correct 2 ms 1628 KB Output is partially correct
6 Partially correct 1 ms 1628 KB Output is partially correct
7 Correct 2 ms 1628 KB Output is correct
8 Partially correct 1 ms 1628 KB Output is partially correct
9 Partially correct 2 ms 1624 KB Output is partially correct
10 Correct 5 ms 1628 KB Output is correct
11 Incorrect 2 ms 1628 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 600 KB Output is partially correct
2 Partially correct 2 ms 1628 KB Output is partially correct
3 Partially correct 1 ms 1628 KB Output is partially correct
4 Partially correct 1 ms 1628 KB Output is partially correct
5 Partially correct 2 ms 1628 KB Output is partially correct
6 Partially correct 1 ms 1628 KB Output is partially correct
7 Correct 2 ms 1628 KB Output is correct
8 Partially correct 1 ms 1628 KB Output is partially correct
9 Partially correct 2 ms 1624 KB Output is partially correct
10 Correct 5 ms 1628 KB Output is correct
11 Incorrect 2 ms 1628 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 600 KB Output is partially correct
2 Partially correct 2 ms 1628 KB Output is partially correct
3 Partially correct 1 ms 1628 KB Output is partially correct
4 Partially correct 1 ms 1628 KB Output is partially correct
5 Partially correct 2 ms 1628 KB Output is partially correct
6 Partially correct 1 ms 1628 KB Output is partially correct
7 Correct 2 ms 1628 KB Output is correct
8 Partially correct 1 ms 1628 KB Output is partially correct
9 Partially correct 2 ms 1624 KB Output is partially correct
10 Correct 5 ms 1628 KB Output is correct
11 Incorrect 2 ms 1628 KB Output isn't correct
12 Halted 0 ms 0 KB -