Submission #533341

# Submission time Handle Problem Language Result Execution time Memory
533341 2022-03-05T14:10:55 Z qwerasdfzxcl Cats or Dogs (JOI18_catdog) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
constexpr int INF = 1e9;
vector<int> adj[100100];
int c[100100], dp[100100][2];

void dfs(int s, int pa = -1){
    dp[s][0] = dp[s][1] = 0;
    for (auto &v:adj[s]) if (v!=pa) dfs(v, s);

    if (c[s]!=1){
        for (auto &v:adj[s]) if (v!=pa){
            dp[s][0] += min(dp[v][0], dp[v][1] + 1);
        }
    }
    else dp[s][0] = INF;

    if (c[s]!=0){
        for (auto &v:adj[s]) if (v!=pa){
            dp[s][1] += min(dp[v][1], dp[v][0] + 1);
        }
    }
    else dp[s][1] = INF;
}

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

    scanf("%d", &q);
    while(q--){
        int op, x;
        scanf("%d %d", &op, &x);
        if (op==1) c[x] = 1;
        else if (op==2) c[x] = 0;
        else c[x] = -1;

        dfs(1);
        printf("%d\n", min(dp[1][0], dp[1][1]));
    }
    return 0;
}

Compilation message

catdog.cpp: In function 'int main()':
catdog.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
catdog.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
catdog.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
catdog.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d %d", &op, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccIOqeQE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc88feLD.o:catdog.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccIOqeQE.o: in function `main':
grader.cpp:(.text.startup+0x1f1): undefined reference to `initialize(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
/usr/bin/ld: grader.cpp:(.text.startup+0x229): undefined reference to `neighbor(int)'
/usr/bin/ld: grader.cpp:(.text.startup+0x26d): undefined reference to `dog(int)'
/usr/bin/ld: grader.cpp:(.text.startup+0x311): undefined reference to `cat(int)'
collect2: error: ld returned 1 exit status