Submission #1235248

#TimeUsernameProblemLanguageResultExecution timeMemory
1235248badge881Spring cleaning (CEOI20_cleaning)C++20
9 / 100
1095 ms836 KiB
#include <bits/stdc++.h> using namespace std; signed main() { int n, q; scanf("%d%d", &n, &q); for (int i = 0; i < n - 1; i++) { int a, b; scanf("%d%d", &a, &b); } for (int i = 0; i < q; i++) { int d; scanf("%d", &d); vector<int> nodeAdded(n - 1, 0); for (int i = 0; i < d; i++) { int node; scanf("%d", &node); nodeAdded[node - 2]++; } int ans = 0, nbleaf = 0, out = -2; for (auto &&i : nodeAdded) { if (i == 0) { nbleaf++, ans++; out = max(1, out + 1); continue; } else nbleaf += i; if (i % 2 == 1) ans += i + 1; else ans += i + 2, out += 2; } if (nbleaf % 2 == 1 or out % 2 == 1) { printf("-1\n"); continue; } if (out == 0) ans += 2; printf("%d\n", ans); } }

Compilation message (stderr)

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