제출 #391326

#제출 시각아이디문제언어결과실행 시간메모리
391326Ruxandra985Cat in a tree (BOI17_catinatree)C++14
100 / 100
220 ms16316 KiB
#include <bits/stdc++.h> #define DIMN 200010 using namespace std; vector <int> v[DIMN]; vector <pair <int , int> > w; int taken[DIMN] , lvl[DIMN]; void dfs (int nod , int tt , int still){ int i , vecin; if (taken[nod] >= still) return; taken[nod] = still; for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i]; if (vecin != tt && taken[vecin] < still - 1) dfs(vecin , nod , still - 1); } } int main() { FILE *fin = stdin; FILE *fout = stdout; int n , d , i , x , sol , nod; fscanf (fin,"%d%d",&n,&d); for (i = 2 ; i <= n ; i++){ fscanf (fin,"%d",&x); x++; v[x].push_back(i); v[i].push_back(x); lvl[i] = 1 + lvl[x]; } for (i = 1 ; i <= n ; i++) w.push_back(make_pair(lvl[i] , i)); sort (w.begin() , w.end()); sol = 0; while (!w.empty()){ nod = w.back().second; w.pop_back(); if (taken[nod]) continue; sol++; dfs(nod , 0 , d); } fprintf (fout,"%d",sol); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp: In function 'void dfs(int, int, int)':
catinatree.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (i = 0 ; i < v[nod].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~
catinatree.cpp: In function 'int main()':
catinatree.cpp:29:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |     fscanf (fin,"%d%d",&n,&d);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
catinatree.cpp:31:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         fscanf (fin,"%d",&x);
      |         ~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...