Submission #342405

#TimeUsernameProblemLanguageResultExecution timeMemory
342405mjhmjh1104Spring cleaning (CEOI20_cleaning)C++14
9 / 100
53 ms7908 KiB
#include <cstdio> #include <vector> #include <algorithm> using namespace std; const int MAX = 100006; int n, q, d, childs[MAX]; vector<int> adj[MAX]; int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n - 1; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; adj[a].push_back(b); adj[b].push_back(a); } scanf("%d", &d); for (int i = 0; i < d; i++) { int x; scanf("%d", &x); x--; childs[x]++; } int cnt = 0; for (int i = 1; i < n; i++) cnt += max(childs[i], 1); if (cnt % 2) return puts("-1"), 0; long long res = 0; for (int i = 1; i < n; i++) if (childs[i] > 2) res += (childs[i] - 1) / 2 * 2, childs[i] -= (childs[i] - 1) / 2 * 2; for (int i = 1; i < n; i++) if (childs[i]) res += childs[i] * 2; else res++; printf("%lld", res); }

Compilation message (stderr)

cleaning.cpp: In function 'int main()':
cleaning.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
cleaning.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
cleaning.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%d", &d);
      |     ~~~~~^~~~~~~~~~
cleaning.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%d", &x); x--;
      |         ~~~~~^~~~~~~~~~
#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...