Submission #304553

#TimeUsernameProblemLanguageResultExecution timeMemory
304553Ruxandra985Spring cleaning (CEOI20_cleaning)C++14
34 / 100
1094 ms16376 KiB
#include <bits/stdc++.h> #define DIMN 200010 using namespace std; int sol , x[DIMN] , propag[DIMN] ,f[DIMN]; vector <int> v[DIMN]; void dfs (int nod , int tt){ int i , vecin; f[nod] = 0; if (v[nod].size() < 2) f[nod] = 1; for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i]; if (vecin != tt){ dfs(vecin , nod); f[nod] += f[vecin]; if (f[vecin] % 2 == 0) sol++; } } } int main() { FILE *fin = stdin; FILE *fout = stdout; int n , q , xx , y , d , i; fscanf (fin,"%d%d",&n,&q); for (i = 1 ; i < n ; i++){ fscanf (fin,"%d%d",&xx,&y); v[xx].push_back(y); v[y].push_back(xx); } for (;q;q--){ fscanf (fin,"%d",&d); for (i = 1 ; i <= d ; i++){ fscanf (fin,"%d",&x[i]); } for (i = 1 ; i <= d ; i++){ v[x[i]].push_back(n + i); } sol = 0; for (i = 1 ; i <= n ; i++){ if (v[i].size() > 1){ dfs (i , 0); /// i e radacina acum if (f[i] % 2 == 1) fprintf (fout,"-1\n"); break; } } if (f[i] % 2 == 0) fprintf (fout,"%d\n",n + d - 1 + sol); for (i = 1 ; i <= d ; i++){ v[x[i]].pop_back(); } } return 0; }

Compilation message (stderr)

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