Submission #680442

# Submission time Handle Problem Language Result Execution time Memory
680442 2023-01-10T21:04:44 Z qwerasdfzxcl Wells (CEOI21_wells) C++17
0 / 100
92 ms 72444 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
int dist[10010][10010], vcnt, n, k;
vector<int> adj[1501500], G[1501500], st;
vector<vector<int>> path;

void dfs(int s, int pa = -1){
    st.push_back(s);
    if ((int)st.size()==k) path.push_back(st);
    dist[st[0]][s] = (int)st.size() - 1;

    for (auto &v:adj[s]) if (v!=pa){
        dfs(v, s);
    }

    st.pop_back();
}

int col[1501500];
int simulate(int s, bool flag = 0){
    vector<int> q = {s}, ch = {s};
    col[s] = 1;

    while(!q.empty()){
        int v = q.back(); q.pop_back();
        for (int i=1;i<=n;i++) if (dist[v][i]==k && !col[i]){
            col[i] = 1;
            q.push_back(i);
            ch.push_back(i);
        }
    }

    int ret = 1;
    for (auto &p:path){
        int cnt = 0;
        for (auto &x:p) if (col[x]) cnt++;
        if (cnt>1){
            for (auto &x:ch) col[x] = 0;
            return 0;
        }

        if (cnt==0) ret = -1;
    }

    if (!flag) for (auto &x:ch) col[x] = 0;
    return ret;
}

int main(){
    scanf("%d %d", &n, &k);
    for (int i=1;i<=n-1;i++){
        int x, y;
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    for (int i=1;i<=n;i++){
        dfs(i);
    }

    for (int i=1;i<=n;i++) if (simulate(i)==1){
        printf("YES\n0\n");
        return 0;
    }
    for (int i=1;i<=n;i++) if (simulate(i, 1)==1){
        printf("YES\n0\n");
        return 0;
    }

    printf("NO\n0\n");
    return 0;
}

Compilation message

wells.cpp: In function 'int main()':
wells.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
wells.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 32 ms 70764 KB Output is partially correct
2 Partially correct 39 ms 71884 KB Output is partially correct
3 Partially correct 34 ms 71892 KB Output is partially correct
4 Partially correct 42 ms 71900 KB Output is partially correct
5 Partially correct 34 ms 71884 KB Output is partially correct
6 Partially correct 35 ms 71900 KB Output is partially correct
7 Correct 60 ms 71836 KB Output is correct
8 Partially correct 38 ms 71780 KB Output is partially correct
9 Partially correct 37 ms 71784 KB Output is partially correct
10 Correct 88 ms 71940 KB Output is correct
11 Partially correct 40 ms 72012 KB Output is partially correct
12 Partially correct 36 ms 71756 KB Output is partially correct
13 Partially correct 34 ms 71764 KB Output is partially correct
14 Partially correct 40 ms 71840 KB Output is partially correct
15 Partially correct 42 ms 71812 KB Output is partially correct
16 Partially correct 43 ms 71756 KB Output is partially correct
17 Partially correct 35 ms 71852 KB Output is partially correct
18 Partially correct 35 ms 71856 KB Output is partially correct
19 Partially correct 36 ms 71816 KB Output is partially correct
20 Correct 50 ms 72020 KB Output is correct
21 Partially correct 34 ms 71804 KB Output is partially correct
22 Partially correct 35 ms 71768 KB Output is partially correct
23 Partially correct 36 ms 71756 KB Output is partially correct
24 Partially correct 38 ms 71936 KB Output is partially correct
25 Partially correct 38 ms 71892 KB Output is partially correct
26 Partially correct 35 ms 71884 KB Output is partially correct
27 Partially correct 39 ms 71908 KB Output is partially correct
28 Correct 57 ms 71928 KB Output is correct
29 Partially correct 37 ms 71992 KB Output is partially correct
30 Partially correct 34 ms 71816 KB Output is partially correct
31 Partially correct 45 ms 71780 KB Output is partially correct
32 Correct 92 ms 71960 KB Output is correct
33 Partially correct 34 ms 71940 KB Output is partially correct
34 Correct 64 ms 72020 KB Output is correct
35 Partially correct 43 ms 72040 KB Output is partially correct
36 Partially correct 35 ms 71760 KB Output is partially correct
37 Partially correct 35 ms 71852 KB Output is partially correct
38 Partially correct 35 ms 71780 KB Output is partially correct
39 Partially correct 38 ms 72404 KB Output is partially correct
40 Partially correct 37 ms 71980 KB Output is partially correct
41 Partially correct 37 ms 71812 KB Output is partially correct
42 Partially correct 39 ms 71892 KB Output is partially correct
43 Partially correct 39 ms 71900 KB Output is partially correct
44 Correct 64 ms 71932 KB Output is correct
45 Partially correct 45 ms 71828 KB Output is partially correct
46 Partially correct 34 ms 71884 KB Output is partially correct
47 Partially correct 40 ms 72444 KB Output is partially correct
48 Partially correct 35 ms 71948 KB Output is partially correct
49 Incorrect 49 ms 71816 KB Output isn't correct
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 32 ms 70764 KB Output is partially correct
2 Partially correct 39 ms 71884 KB Output is partially correct
3 Partially correct 34 ms 71892 KB Output is partially correct
4 Partially correct 42 ms 71900 KB Output is partially correct
5 Partially correct 34 ms 71884 KB Output is partially correct
6 Partially correct 35 ms 71900 KB Output is partially correct
7 Correct 60 ms 71836 KB Output is correct
8 Partially correct 38 ms 71780 KB Output is partially correct
9 Partially correct 37 ms 71784 KB Output is partially correct
10 Correct 88 ms 71940 KB Output is correct
11 Partially correct 40 ms 72012 KB Output is partially correct
12 Partially correct 36 ms 71756 KB Output is partially correct
13 Partially correct 34 ms 71764 KB Output is partially correct
14 Partially correct 40 ms 71840 KB Output is partially correct
15 Partially correct 42 ms 71812 KB Output is partially correct
16 Partially correct 43 ms 71756 KB Output is partially correct
17 Partially correct 35 ms 71852 KB Output is partially correct
18 Partially correct 35 ms 71856 KB Output is partially correct
19 Partially correct 36 ms 71816 KB Output is partially correct
20 Correct 50 ms 72020 KB Output is correct
21 Partially correct 34 ms 71804 KB Output is partially correct
22 Partially correct 35 ms 71768 KB Output is partially correct
23 Partially correct 36 ms 71756 KB Output is partially correct
24 Partially correct 38 ms 71936 KB Output is partially correct
25 Partially correct 38 ms 71892 KB Output is partially correct
26 Partially correct 35 ms 71884 KB Output is partially correct
27 Partially correct 39 ms 71908 KB Output is partially correct
28 Correct 57 ms 71928 KB Output is correct
29 Partially correct 37 ms 71992 KB Output is partially correct
30 Partially correct 34 ms 71816 KB Output is partially correct
31 Partially correct 45 ms 71780 KB Output is partially correct
32 Correct 92 ms 71960 KB Output is correct
33 Partially correct 34 ms 71940 KB Output is partially correct
34 Correct 64 ms 72020 KB Output is correct
35 Partially correct 43 ms 72040 KB Output is partially correct
36 Partially correct 35 ms 71760 KB Output is partially correct
37 Partially correct 35 ms 71852 KB Output is partially correct
38 Partially correct 35 ms 71780 KB Output is partially correct
39 Partially correct 38 ms 72404 KB Output is partially correct
40 Partially correct 37 ms 71980 KB Output is partially correct
41 Partially correct 37 ms 71812 KB Output is partially correct
42 Partially correct 39 ms 71892 KB Output is partially correct
43 Partially correct 39 ms 71900 KB Output is partially correct
44 Correct 64 ms 71932 KB Output is correct
45 Partially correct 45 ms 71828 KB Output is partially correct
46 Partially correct 34 ms 71884 KB Output is partially correct
47 Partially correct 40 ms 72444 KB Output is partially correct
48 Partially correct 35 ms 71948 KB Output is partially correct
49 Incorrect 49 ms 71816 KB Output isn't correct
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 32 ms 70764 KB Output is partially correct
2 Partially correct 39 ms 71884 KB Output is partially correct
3 Partially correct 34 ms 71892 KB Output is partially correct
4 Partially correct 42 ms 71900 KB Output is partially correct
5 Partially correct 34 ms 71884 KB Output is partially correct
6 Partially correct 35 ms 71900 KB Output is partially correct
7 Correct 60 ms 71836 KB Output is correct
8 Partially correct 38 ms 71780 KB Output is partially correct
9 Partially correct 37 ms 71784 KB Output is partially correct
10 Correct 88 ms 71940 KB Output is correct
11 Partially correct 40 ms 72012 KB Output is partially correct
12 Partially correct 36 ms 71756 KB Output is partially correct
13 Partially correct 34 ms 71764 KB Output is partially correct
14 Partially correct 40 ms 71840 KB Output is partially correct
15 Partially correct 42 ms 71812 KB Output is partially correct
16 Partially correct 43 ms 71756 KB Output is partially correct
17 Partially correct 35 ms 71852 KB Output is partially correct
18 Partially correct 35 ms 71856 KB Output is partially correct
19 Partially correct 36 ms 71816 KB Output is partially correct
20 Correct 50 ms 72020 KB Output is correct
21 Partially correct 34 ms 71804 KB Output is partially correct
22 Partially correct 35 ms 71768 KB Output is partially correct
23 Partially correct 36 ms 71756 KB Output is partially correct
24 Partially correct 38 ms 71936 KB Output is partially correct
25 Partially correct 38 ms 71892 KB Output is partially correct
26 Partially correct 35 ms 71884 KB Output is partially correct
27 Partially correct 39 ms 71908 KB Output is partially correct
28 Correct 57 ms 71928 KB Output is correct
29 Partially correct 37 ms 71992 KB Output is partially correct
30 Partially correct 34 ms 71816 KB Output is partially correct
31 Partially correct 45 ms 71780 KB Output is partially correct
32 Correct 92 ms 71960 KB Output is correct
33 Partially correct 34 ms 71940 KB Output is partially correct
34 Correct 64 ms 72020 KB Output is correct
35 Partially correct 43 ms 72040 KB Output is partially correct
36 Partially correct 35 ms 71760 KB Output is partially correct
37 Partially correct 35 ms 71852 KB Output is partially correct
38 Partially correct 35 ms 71780 KB Output is partially correct
39 Partially correct 38 ms 72404 KB Output is partially correct
40 Partially correct 37 ms 71980 KB Output is partially correct
41 Partially correct 37 ms 71812 KB Output is partially correct
42 Partially correct 39 ms 71892 KB Output is partially correct
43 Partially correct 39 ms 71900 KB Output is partially correct
44 Correct 64 ms 71932 KB Output is correct
45 Partially correct 45 ms 71828 KB Output is partially correct
46 Partially correct 34 ms 71884 KB Output is partially correct
47 Partially correct 40 ms 72444 KB Output is partially correct
48 Partially correct 35 ms 71948 KB Output is partially correct
49 Incorrect 49 ms 71816 KB Output isn't correct
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 32 ms 70764 KB Output is partially correct
2 Partially correct 39 ms 71884 KB Output is partially correct
3 Partially correct 34 ms 71892 KB Output is partially correct
4 Partially correct 42 ms 71900 KB Output is partially correct
5 Partially correct 34 ms 71884 KB Output is partially correct
6 Partially correct 35 ms 71900 KB Output is partially correct
7 Correct 60 ms 71836 KB Output is correct
8 Partially correct 38 ms 71780 KB Output is partially correct
9 Partially correct 37 ms 71784 KB Output is partially correct
10 Correct 88 ms 71940 KB Output is correct
11 Partially correct 40 ms 72012 KB Output is partially correct
12 Partially correct 36 ms 71756 KB Output is partially correct
13 Partially correct 34 ms 71764 KB Output is partially correct
14 Partially correct 40 ms 71840 KB Output is partially correct
15 Partially correct 42 ms 71812 KB Output is partially correct
16 Partially correct 43 ms 71756 KB Output is partially correct
17 Partially correct 35 ms 71852 KB Output is partially correct
18 Partially correct 35 ms 71856 KB Output is partially correct
19 Partially correct 36 ms 71816 KB Output is partially correct
20 Correct 50 ms 72020 KB Output is correct
21 Partially correct 34 ms 71804 KB Output is partially correct
22 Partially correct 35 ms 71768 KB Output is partially correct
23 Partially correct 36 ms 71756 KB Output is partially correct
24 Partially correct 38 ms 71936 KB Output is partially correct
25 Partially correct 38 ms 71892 KB Output is partially correct
26 Partially correct 35 ms 71884 KB Output is partially correct
27 Partially correct 39 ms 71908 KB Output is partially correct
28 Correct 57 ms 71928 KB Output is correct
29 Partially correct 37 ms 71992 KB Output is partially correct
30 Partially correct 34 ms 71816 KB Output is partially correct
31 Partially correct 45 ms 71780 KB Output is partially correct
32 Correct 92 ms 71960 KB Output is correct
33 Partially correct 34 ms 71940 KB Output is partially correct
34 Correct 64 ms 72020 KB Output is correct
35 Partially correct 43 ms 72040 KB Output is partially correct
36 Partially correct 35 ms 71760 KB Output is partially correct
37 Partially correct 35 ms 71852 KB Output is partially correct
38 Partially correct 35 ms 71780 KB Output is partially correct
39 Partially correct 38 ms 72404 KB Output is partially correct
40 Partially correct 37 ms 71980 KB Output is partially correct
41 Partially correct 37 ms 71812 KB Output is partially correct
42 Partially correct 39 ms 71892 KB Output is partially correct
43 Partially correct 39 ms 71900 KB Output is partially correct
44 Correct 64 ms 71932 KB Output is correct
45 Partially correct 45 ms 71828 KB Output is partially correct
46 Partially correct 34 ms 71884 KB Output is partially correct
47 Partially correct 40 ms 72444 KB Output is partially correct
48 Partially correct 35 ms 71948 KB Output is partially correct
49 Incorrect 49 ms 71816 KB Output isn't correct
50 Halted 0 ms 0 KB -