Submission #105251

#TimeUsernameProblemLanguageResultExecution timeMemory
105251antimirageDesignated Cities (JOI19_designated_cities)C++14
0 / 100
304 ms21112 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb push_back #define all(s) s.begin(), s.end() using namespace std; const int N = 2e5 + 5; int n, q, x, y, c, d; long long ans, pref[N], ALL, res; vector < vector < pair <int, pair <int, int> > > > g; void dfs (int v, int p = 0) { for (auto to : g[v]){ if (to.fr == p) continue; pref[to.fr] = pref[v] + to.sc.fr - to.sc.sc; dfs(to.fr, v); ans += to.sc.sc; ALL += to.sc.fr; ALL += to.sc.sc; } } main(){ cin >> n; g.resize(n + 1); for (int i = 1; i < n; i++){ scanf("%d%d%d%d", &x, &y, &c, &d); g[x].pb( mk( y, mk(c, d) ) ); g[y].pb( mk( x, mk(c, d) ) ); } dfs(1); for (int i = 1; i <= n; i++){ res = max(res, ans + pref[i]); } cin >> q; while (q--){ cout << ALL - res << endl; } } /** 4 1 2 1 2 1 3 3 4 1 4 5 6 **/

Compilation message (stderr)

designated_cities.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
designated_cities.cpp: In function 'int main()':
designated_cities.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &x, &y, &c, &d);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...