Submission #72958

#TimeUsernameProblemLanguageResultExecution timeMemory
72958ekremCats or Dogs (JOI18_catdog)C++98
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "catdog.h" #define st first #define nd second #define mp make_pair #define pb push_back #define inf 1000000007 #define N 1000005 using namespace std; typedef vector < int > vi; typedef pair < int , int > ii; int a[N], par[22][N]; ii dp[N]; vi gg[N], g[N]; void f(int node){ int bir = 0, iki = 0; for(int i = 0; i < g[node].size(); i++){ int coc = g[node][i]; f(coc); bir += dp[coc].st; iki += dp[coc].nd; } if(a[node] == 1) iki = inf; if(a[node] == 2) bir = inf; // cout << node << " -> " << bir << " " << iki << endl; //bir = f(node, 0) //iki = f(node, 1) dp[node].st = min(bir, iki + 1); dp[node].nd = min(bir + 1, iki); } void hazirla(int node, int pr){ par[0][node] = pr; for(int i = 0; i < gg[node].size(); i++) if(gg[node][i] != pr){ g[node].pb(gg[node][i]); hazirla(gg[node][i], node); } } void initialize(int n, vi a, vi b){ for(int i = 0; i < n - 1; i++){ gg[a[i]].pb(b[i]); gg[b[i]].pb(a[i]); } hazirla(1, 0); } int cat(int v){//cout << "AMK:\n"; a[v] = 1; f(1); return min(dp[1].st, dp[1].nd); } int dog(int v){//cout << "AMK:\n"; a[v] = 2; f(1); return min(dp[1].st, dp[1].nd); } int neighbor(int v){//cout << "AMK:\n"; a[v] = 0; f(1); return min(dp[1].st, dp[1].nd); } int main(){ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int n, q; scanf("%d",&n); vi a(n - 1), b(n - 1); for(int i = 0; i < n - 1; i++) scanf("%d %d",&a[i] ,&b[i]); scanf("%d",&q); vi t(q), v(q); for(int i = 0; i < q; i++) scanf("%d %d",&t[i] ,&v[i]); initialize(n, a, b); vi ans(q); for(int i = 0; i < q; i++){ if(t[i] == 1) ans[i] = cat(v[i]); else if(t[i] == 2) ans[i] = dog(v[i]); else ans[i] = neighbor(v[i]); } for(int i = 0; i < q; i++) printf("%d\n",ans[i]); return 0; }

Compilation message (stderr)

catdog.cpp: In function 'void f(int)':
catdog.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[node].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
catdog.cpp: In function 'void hazirla(int, int)':
catdog.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < gg[node].size(); i++)
                 ~~^~~~~~~~~~~~~~~~~
catdog.cpp: In function 'int main()':
catdog.cpp:74:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("in.txt", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
catdog.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("out.txt", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
catdog.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
catdog.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i] ,&b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
catdog.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
catdog.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&t[i] ,&v[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
/tmp/cc1r6PCW.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cckXSmlv.o:catdog.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status