답안 #680436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680436 2023-01-10T20:56:47 Z qwerasdfzxcl Wells (CEOI21_wells) C++17
0 / 100
58 ms 72264 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];
bool simulate(int s){
    vector<int> q = {s};
    fill(col+1, col+n+1, 0);
    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);
        }
    }

    vector<vector<int>> npath;
    for (auto &p:path){
        int cnt = 0;
        for (auto &x:p) if (col[x]) cnt++;
        if (cnt>1) return 0;

        if (cnt==0) npath.push_back(p);
    }
    swap(path, npath);
    return 1;
}

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) && path.empty()){
        printf("YES\n0\n");
        return 0;
    }
    printf("NO\n0\n");
    return 0;
}

Compilation message

wells.cpp: In function 'int main()':
wells.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
wells.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 37 ms 70772 KB Output is partially correct
2 Partially correct 37 ms 71932 KB Output is partially correct
3 Partially correct 34 ms 71876 KB Output is partially correct
4 Partially correct 33 ms 71892 KB Output is partially correct
5 Partially correct 33 ms 71880 KB Output is partially correct
6 Partially correct 39 ms 71876 KB Output is partially correct
7 Correct 45 ms 71756 KB Output is correct
8 Partially correct 35 ms 71748 KB Output is partially correct
9 Partially correct 33 ms 71800 KB Output is partially correct
10 Correct 58 ms 71864 KB Output is correct
11 Partially correct 37 ms 71960 KB Output is partially correct
12 Partially correct 33 ms 71820 KB Output is partially correct
13 Partially correct 34 ms 71840 KB Output is partially correct
14 Partially correct 37 ms 71884 KB Output is partially correct
15 Partially correct 36 ms 71880 KB Output is partially correct
16 Partially correct 34 ms 71836 KB Output is partially correct
17 Partially correct 36 ms 71884 KB Output is partially correct
18 Partially correct 34 ms 71892 KB Output is partially correct
19 Partially correct 34 ms 71828 KB Output is partially correct
20 Incorrect 45 ms 72264 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 37 ms 70772 KB Output is partially correct
2 Partially correct 37 ms 71932 KB Output is partially correct
3 Partially correct 34 ms 71876 KB Output is partially correct
4 Partially correct 33 ms 71892 KB Output is partially correct
5 Partially correct 33 ms 71880 KB Output is partially correct
6 Partially correct 39 ms 71876 KB Output is partially correct
7 Correct 45 ms 71756 KB Output is correct
8 Partially correct 35 ms 71748 KB Output is partially correct
9 Partially correct 33 ms 71800 KB Output is partially correct
10 Correct 58 ms 71864 KB Output is correct
11 Partially correct 37 ms 71960 KB Output is partially correct
12 Partially correct 33 ms 71820 KB Output is partially correct
13 Partially correct 34 ms 71840 KB Output is partially correct
14 Partially correct 37 ms 71884 KB Output is partially correct
15 Partially correct 36 ms 71880 KB Output is partially correct
16 Partially correct 34 ms 71836 KB Output is partially correct
17 Partially correct 36 ms 71884 KB Output is partially correct
18 Partially correct 34 ms 71892 KB Output is partially correct
19 Partially correct 34 ms 71828 KB Output is partially correct
20 Incorrect 45 ms 72264 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 37 ms 70772 KB Output is partially correct
2 Partially correct 37 ms 71932 KB Output is partially correct
3 Partially correct 34 ms 71876 KB Output is partially correct
4 Partially correct 33 ms 71892 KB Output is partially correct
5 Partially correct 33 ms 71880 KB Output is partially correct
6 Partially correct 39 ms 71876 KB Output is partially correct
7 Correct 45 ms 71756 KB Output is correct
8 Partially correct 35 ms 71748 KB Output is partially correct
9 Partially correct 33 ms 71800 KB Output is partially correct
10 Correct 58 ms 71864 KB Output is correct
11 Partially correct 37 ms 71960 KB Output is partially correct
12 Partially correct 33 ms 71820 KB Output is partially correct
13 Partially correct 34 ms 71840 KB Output is partially correct
14 Partially correct 37 ms 71884 KB Output is partially correct
15 Partially correct 36 ms 71880 KB Output is partially correct
16 Partially correct 34 ms 71836 KB Output is partially correct
17 Partially correct 36 ms 71884 KB Output is partially correct
18 Partially correct 34 ms 71892 KB Output is partially correct
19 Partially correct 34 ms 71828 KB Output is partially correct
20 Incorrect 45 ms 72264 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 37 ms 70772 KB Output is partially correct
2 Partially correct 37 ms 71932 KB Output is partially correct
3 Partially correct 34 ms 71876 KB Output is partially correct
4 Partially correct 33 ms 71892 KB Output is partially correct
5 Partially correct 33 ms 71880 KB Output is partially correct
6 Partially correct 39 ms 71876 KB Output is partially correct
7 Correct 45 ms 71756 KB Output is correct
8 Partially correct 35 ms 71748 KB Output is partially correct
9 Partially correct 33 ms 71800 KB Output is partially correct
10 Correct 58 ms 71864 KB Output is correct
11 Partially correct 37 ms 71960 KB Output is partially correct
12 Partially correct 33 ms 71820 KB Output is partially correct
13 Partially correct 34 ms 71840 KB Output is partially correct
14 Partially correct 37 ms 71884 KB Output is partially correct
15 Partially correct 36 ms 71880 KB Output is partially correct
16 Partially correct 34 ms 71836 KB Output is partially correct
17 Partially correct 36 ms 71884 KB Output is partially correct
18 Partially correct 34 ms 71892 KB Output is partially correct
19 Partially correct 34 ms 71828 KB Output is partially correct
20 Incorrect 45 ms 72264 KB Output isn't correct
21 Halted 0 ms 0 KB -