답안 #993842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993842 2024-06-06T13:53:17 Z danikoynov Wells (CEOI21_wells) C++14
0 / 100
137 ms 17244 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];
int from[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)
            {
                from[u] = v;
                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)
            {
                from[u] = v;
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}

int bruh[maxn][maxn];
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 v = 1; v <= n; v ++)
    {
        for (int u = v; u <= n; u ++)
        {
           // cout << v << " : " << u << endl;
            if (path[v][u] >= k - 1)
            {
               /// cout << v << " :" << u << endl;
                bfs(v);
                ///cout << "shiit" << endl;
                //for (int i = 1; i <= n; i ++)
                {
                  //  cout << "vertex " << i << " " << from[i] << endl;
                }
                int cur = u;
                vector < int > st;
                while(cur != v)
                {
                    ///cout << cur << endl;
                    st.push_back(cur);
                    cur = from[cur];
                }
                st.push_back(cur);
                for (int d : st)
                    for (int p : st)
                    bruh[d][p] = bruh[p][d] = 1;
            }
        }
    }

    /**for (int i = 1; i <= n; i ++, cout << endl)
        for (int j = 1; j <= n; j ++)
        cout << bruh[i][j] << " ";*/

    bfs(1);
    int mx = 1;
    for (int i = 1; i <= n; i ++)
        if (dist[mx] < dist[i])
        mx = i;

    bfs(mx);
    int len = 0;
    for (int i = 1; i <= n; i ++)
        len = max(len, dist[i]);


    if (len < k - 1)
    {
        cout << "YES" << endl;
        cout << 0 << endl;
        return;
    }
    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 && bruh[st[i]][st[j]] == 1)
            {
                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:157:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |         for (int i = 0; i < st.size(); i ++)
      |                         ~~^~~~~~~~~~~
wells.cpp:158:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |             for (int j = i + 1; j < st.size(); j ++)
      |                                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Output is partially correct
2 Partially correct 47 ms 16984 KB Output is partially correct
3 Partially correct 44 ms 17100 KB Output is partially correct
4 Partially correct 51 ms 16984 KB Output is partially correct
5 Partially correct 32 ms 16988 KB Output is partially correct
6 Partially correct 137 ms 17116 KB Output is partially correct
7 Correct 63 ms 17100 KB Output is correct
8 Partially correct 36 ms 16984 KB Output is partially correct
9 Partially correct 55 ms 16984 KB Output is partially correct
10 Correct 59 ms 17100 KB Output is correct
11 Partially correct 25 ms 16988 KB Output is partially correct
12 Partially correct 2 ms 8796 KB Output is partially correct
13 Partially correct 66 ms 17108 KB Output is partially correct
14 Partially correct 55 ms 16988 KB Output is partially correct
15 Partially correct 86 ms 16988 KB Output is partially correct
16 Partially correct 5 ms 16984 KB Output is partially correct
17 Partially correct 11 ms 16988 KB Output is partially correct
18 Partially correct 19 ms 16988 KB Output is partially correct
19 Partially correct 29 ms 17136 KB Output is partially correct
20 Correct 24 ms 16988 KB Output is correct
21 Partially correct 51 ms 17104 KB Output is partially correct
22 Partially correct 4 ms 17096 KB Output is partially correct
23 Partially correct 8 ms 17132 KB Output is partially correct
24 Partially correct 6 ms 16988 KB Output is partially correct
25 Partially correct 48 ms 16988 KB Output is partially correct
26 Partially correct 32 ms 17096 KB Output is partially correct
27 Partially correct 99 ms 16988 KB Output is partially correct
28 Correct 53 ms 16984 KB Output is correct
29 Partially correct 24 ms 16988 KB Output is partially correct
30 Partially correct 36 ms 16988 KB Output is partially correct
31 Partially correct 36 ms 16988 KB Output is partially correct
32 Correct 26 ms 16984 KB Output is correct
33 Partially correct 20 ms 17132 KB Output is partially correct
34 Correct 28 ms 16988 KB Output is correct
35 Partially correct 19 ms 16988 KB Output is partially correct
36 Partially correct 31 ms 17132 KB Output is partially correct
37 Partially correct 87 ms 16988 KB Output is partially correct
38 Partially correct 75 ms 16988 KB Output is partially correct
39 Partially correct 32 ms 16988 KB Output is partially correct
40 Partially correct 27 ms 16988 KB Output is partially correct
41 Partially correct 20 ms 17128 KB Output is partially correct
42 Partially correct 21 ms 17128 KB Output is partially correct
43 Partially correct 48 ms 17244 KB Output is partially correct
44 Correct 27 ms 17132 KB Output is correct
45 Partially correct 26 ms 16988 KB Output is partially correct
46 Partially correct 66 ms 16984 KB Output is partially correct
47 Partially correct 26 ms 16988 KB Output is partially correct
48 Partially correct 17 ms 16988 KB Output is partially correct
49 Incorrect 45 ms 17108 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Output is partially correct
2 Partially correct 47 ms 16984 KB Output is partially correct
3 Partially correct 44 ms 17100 KB Output is partially correct
4 Partially correct 51 ms 16984 KB Output is partially correct
5 Partially correct 32 ms 16988 KB Output is partially correct
6 Partially correct 137 ms 17116 KB Output is partially correct
7 Correct 63 ms 17100 KB Output is correct
8 Partially correct 36 ms 16984 KB Output is partially correct
9 Partially correct 55 ms 16984 KB Output is partially correct
10 Correct 59 ms 17100 KB Output is correct
11 Partially correct 25 ms 16988 KB Output is partially correct
12 Partially correct 2 ms 8796 KB Output is partially correct
13 Partially correct 66 ms 17108 KB Output is partially correct
14 Partially correct 55 ms 16988 KB Output is partially correct
15 Partially correct 86 ms 16988 KB Output is partially correct
16 Partially correct 5 ms 16984 KB Output is partially correct
17 Partially correct 11 ms 16988 KB Output is partially correct
18 Partially correct 19 ms 16988 KB Output is partially correct
19 Partially correct 29 ms 17136 KB Output is partially correct
20 Correct 24 ms 16988 KB Output is correct
21 Partially correct 51 ms 17104 KB Output is partially correct
22 Partially correct 4 ms 17096 KB Output is partially correct
23 Partially correct 8 ms 17132 KB Output is partially correct
24 Partially correct 6 ms 16988 KB Output is partially correct
25 Partially correct 48 ms 16988 KB Output is partially correct
26 Partially correct 32 ms 17096 KB Output is partially correct
27 Partially correct 99 ms 16988 KB Output is partially correct
28 Correct 53 ms 16984 KB Output is correct
29 Partially correct 24 ms 16988 KB Output is partially correct
30 Partially correct 36 ms 16988 KB Output is partially correct
31 Partially correct 36 ms 16988 KB Output is partially correct
32 Correct 26 ms 16984 KB Output is correct
33 Partially correct 20 ms 17132 KB Output is partially correct
34 Correct 28 ms 16988 KB Output is correct
35 Partially correct 19 ms 16988 KB Output is partially correct
36 Partially correct 31 ms 17132 KB Output is partially correct
37 Partially correct 87 ms 16988 KB Output is partially correct
38 Partially correct 75 ms 16988 KB Output is partially correct
39 Partially correct 32 ms 16988 KB Output is partially correct
40 Partially correct 27 ms 16988 KB Output is partially correct
41 Partially correct 20 ms 17128 KB Output is partially correct
42 Partially correct 21 ms 17128 KB Output is partially correct
43 Partially correct 48 ms 17244 KB Output is partially correct
44 Correct 27 ms 17132 KB Output is correct
45 Partially correct 26 ms 16988 KB Output is partially correct
46 Partially correct 66 ms 16984 KB Output is partially correct
47 Partially correct 26 ms 16988 KB Output is partially correct
48 Partially correct 17 ms 16988 KB Output is partially correct
49 Incorrect 45 ms 17108 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Output is partially correct
2 Partially correct 47 ms 16984 KB Output is partially correct
3 Partially correct 44 ms 17100 KB Output is partially correct
4 Partially correct 51 ms 16984 KB Output is partially correct
5 Partially correct 32 ms 16988 KB Output is partially correct
6 Partially correct 137 ms 17116 KB Output is partially correct
7 Correct 63 ms 17100 KB Output is correct
8 Partially correct 36 ms 16984 KB Output is partially correct
9 Partially correct 55 ms 16984 KB Output is partially correct
10 Correct 59 ms 17100 KB Output is correct
11 Partially correct 25 ms 16988 KB Output is partially correct
12 Partially correct 2 ms 8796 KB Output is partially correct
13 Partially correct 66 ms 17108 KB Output is partially correct
14 Partially correct 55 ms 16988 KB Output is partially correct
15 Partially correct 86 ms 16988 KB Output is partially correct
16 Partially correct 5 ms 16984 KB Output is partially correct
17 Partially correct 11 ms 16988 KB Output is partially correct
18 Partially correct 19 ms 16988 KB Output is partially correct
19 Partially correct 29 ms 17136 KB Output is partially correct
20 Correct 24 ms 16988 KB Output is correct
21 Partially correct 51 ms 17104 KB Output is partially correct
22 Partially correct 4 ms 17096 KB Output is partially correct
23 Partially correct 8 ms 17132 KB Output is partially correct
24 Partially correct 6 ms 16988 KB Output is partially correct
25 Partially correct 48 ms 16988 KB Output is partially correct
26 Partially correct 32 ms 17096 KB Output is partially correct
27 Partially correct 99 ms 16988 KB Output is partially correct
28 Correct 53 ms 16984 KB Output is correct
29 Partially correct 24 ms 16988 KB Output is partially correct
30 Partially correct 36 ms 16988 KB Output is partially correct
31 Partially correct 36 ms 16988 KB Output is partially correct
32 Correct 26 ms 16984 KB Output is correct
33 Partially correct 20 ms 17132 KB Output is partially correct
34 Correct 28 ms 16988 KB Output is correct
35 Partially correct 19 ms 16988 KB Output is partially correct
36 Partially correct 31 ms 17132 KB Output is partially correct
37 Partially correct 87 ms 16988 KB Output is partially correct
38 Partially correct 75 ms 16988 KB Output is partially correct
39 Partially correct 32 ms 16988 KB Output is partially correct
40 Partially correct 27 ms 16988 KB Output is partially correct
41 Partially correct 20 ms 17128 KB Output is partially correct
42 Partially correct 21 ms 17128 KB Output is partially correct
43 Partially correct 48 ms 17244 KB Output is partially correct
44 Correct 27 ms 17132 KB Output is correct
45 Partially correct 26 ms 16988 KB Output is partially correct
46 Partially correct 66 ms 16984 KB Output is partially correct
47 Partially correct 26 ms 16988 KB Output is partially correct
48 Partially correct 17 ms 16988 KB Output is partially correct
49 Incorrect 45 ms 17108 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Output is partially correct
2 Partially correct 47 ms 16984 KB Output is partially correct
3 Partially correct 44 ms 17100 KB Output is partially correct
4 Partially correct 51 ms 16984 KB Output is partially correct
5 Partially correct 32 ms 16988 KB Output is partially correct
6 Partially correct 137 ms 17116 KB Output is partially correct
7 Correct 63 ms 17100 KB Output is correct
8 Partially correct 36 ms 16984 KB Output is partially correct
9 Partially correct 55 ms 16984 KB Output is partially correct
10 Correct 59 ms 17100 KB Output is correct
11 Partially correct 25 ms 16988 KB Output is partially correct
12 Partially correct 2 ms 8796 KB Output is partially correct
13 Partially correct 66 ms 17108 KB Output is partially correct
14 Partially correct 55 ms 16988 KB Output is partially correct
15 Partially correct 86 ms 16988 KB Output is partially correct
16 Partially correct 5 ms 16984 KB Output is partially correct
17 Partially correct 11 ms 16988 KB Output is partially correct
18 Partially correct 19 ms 16988 KB Output is partially correct
19 Partially correct 29 ms 17136 KB Output is partially correct
20 Correct 24 ms 16988 KB Output is correct
21 Partially correct 51 ms 17104 KB Output is partially correct
22 Partially correct 4 ms 17096 KB Output is partially correct
23 Partially correct 8 ms 17132 KB Output is partially correct
24 Partially correct 6 ms 16988 KB Output is partially correct
25 Partially correct 48 ms 16988 KB Output is partially correct
26 Partially correct 32 ms 17096 KB Output is partially correct
27 Partially correct 99 ms 16988 KB Output is partially correct
28 Correct 53 ms 16984 KB Output is correct
29 Partially correct 24 ms 16988 KB Output is partially correct
30 Partially correct 36 ms 16988 KB Output is partially correct
31 Partially correct 36 ms 16988 KB Output is partially correct
32 Correct 26 ms 16984 KB Output is correct
33 Partially correct 20 ms 17132 KB Output is partially correct
34 Correct 28 ms 16988 KB Output is correct
35 Partially correct 19 ms 16988 KB Output is partially correct
36 Partially correct 31 ms 17132 KB Output is partially correct
37 Partially correct 87 ms 16988 KB Output is partially correct
38 Partially correct 75 ms 16988 KB Output is partially correct
39 Partially correct 32 ms 16988 KB Output is partially correct
40 Partially correct 27 ms 16988 KB Output is partially correct
41 Partially correct 20 ms 17128 KB Output is partially correct
42 Partially correct 21 ms 17128 KB Output is partially correct
43 Partially correct 48 ms 17244 KB Output is partially correct
44 Correct 27 ms 17132 KB Output is correct
45 Partially correct 26 ms 16988 KB Output is partially correct
46 Partially correct 66 ms 16984 KB Output is partially correct
47 Partially correct 26 ms 16988 KB Output is partially correct
48 Partially correct 17 ms 16988 KB Output is partially correct
49 Incorrect 45 ms 17108 KB Output isn't correct
50 Halted 0 ms 0 KB -