Submission #876823

#TimeUsernameProblemLanguageResultExecution timeMemory
876823overwatch9Sjekira (COCI20_sjekira)C++17
0 / 110
0 ms348 KiB
//subtask3 #include <iostream> #include <vector> #include <set> using namespace std; using ll = long long; vector <bool> blocked; vector <vector <int>> adj; vector <int> col; int dfs(int s, int p) { int ans = col[s]; for (auto i : adj[s]) { if (!blocked[i] && i != p) ans = max(ans, dfs(i, s)); } return ans; } int main() { freopen("in.txt", "r", stdin); int n; cin >> n; adj.resize(n+1); col.resize(n+1); multiset <pair <int, int>> s; for (int i = 1; i <= n; i++) { int t; cin >> t; col[i] = t; s.insert({t, i}); } for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } blocked.resize(n+1); ll ans = 0; while (!s.empty()) { ll mx = s.rbegin()->first, pos = s.rbegin()->second; s.erase(--s.end()); ll added = 0; for (auto i : adj[pos]) { if (!blocked[i]) { added++; ans += dfs(i, pos); } } blocked[pos] = true; ans += mx * added; } cout << ans << '\n'; }

Compilation message (stderr)

sjekira.cpp: In function 'int main()':
sjekira.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...