Submission #48463

#TimeUsernameProblemLanguageResultExecution timeMemory
48463WLZPaprike (COI18_paprike)C++17
13 / 100
72 ms20108 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef long long ll; const int INF = 1e9; const int MAXN = 1e5 + 5; const ll LINF = 1e18; const double pi = acos(-1); const double EPS = 1e-9; template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>; template <class T> using MaxPQ = priority_queue<T>; int n; ll k; int a[MAXN]; vector< vector<int> > g; bitset<MAXN> vis; void bfs(int s) { queue<int> q; q.push(s); ll curSize = a[s]; vis[s] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int& v : g[u]) { if (!vis[v] && (ll) a[v] + curSize <= k) { q.push(v); curSize += a[v]; vis[v] = 1; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); scanf("%d %lld", &n, &k); g.assign(n, vector<int>()); for (int i = 0; i < n; i++) scanf("%d", a + i); for (int i = 0; i < n - 1; i++) { int x, y; scanf("%d %d", &x, &y); --x; --y; g[x].emplace_back(y); g[y].emplace_back(x); } int ans = 0; for (int i = 0; i < n; i++) { if ((int) g[i].size() == 1 && !vis[i]) { ans++; bfs(i); } } for (int i = 0; i < n; i++) { if (!vis[i]) { ans++; bfs(i); } } printf("%d\n", ans - 1); return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
paprike.cpp:40:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < n; i++) scanf("%d", a + i);
                                 ~~~~~^~~~~~~~~~~~~
paprike.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y); --x; --y;
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...