Submission #1009740

#TimeUsernameProblemLanguageResultExecution timeMemory
1009740CookieRoad Closures (APIO21_roads)C++14
0 / 100
2045 ms24896 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair //#define int long long typedef unsigned long long ull; //const int x[4] = {0, 0, 1, -1}; //const int y[4] = {1, -1, 0, 0}; const int mxn = 2e5 + 5; const ll mod = 998244353, mod2 = 1e9 + 1977, inf = 1e17 + 1; struct E{ int u, v, w; }; vt<E>edge[mxn + 1]; vt<int>node; int n; int deg[mxn + 1]; vt<pll>adj[mxn + 1]; vt<ll>ans; bool vis[mxn + 1]; int dfs(int s, int need){ vis[s] = 1; int sus = deg[s] - need; for(auto [i, w]: adj[s]){ if(!vis[i]){ sus -= dfs(i, need); } } if(sus <= 0)return(0); ans[need] += sus; return(1); } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; bool ok = 1; ans.resize(n, 0); for(int i = 0; i < n - 1; i++){ U[i]++; V[i]++; ok &= (U[i] == 1); adj[U[i]].pb(mpp(V[i], W[i])); adj[V[i]].pb(mpp(U[i], W[i])); deg[U[i]]++; deg[V[i]]++; } for(int i = 0; i < n - 1; i++){ for(int j = min(deg[U[i]], deg[V[i]]) - 1; j >= 0; j--){ edge[i].pb({U[i], V[i], W[i]}); node.pb(U[i]); node.pb(V[i]); } } for(int i = 0; i < n; i++){ for(auto [u, v, w]: edge[i]){ //cout << i << " " << u << " " << v << " " << w << "\n"; adj[u].pb(mpp(v, w)); adj[v].pb(mpp(u, w)); } for(auto u: node){ if(vis[u] == 0){ dfs(u, i); } } for(auto u: node){ adj[u].clear(); vis[u] = 0; } } return(ans); } /* int main() { int N; assert(1 == scanf("%d", &N)); std::vector<int> U(N - 1), V(N - 1), W(N - 1); for (int i = 0; i < N - 1; ++i) { assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i])); } std::vector<long long> closure_costs = minimum_closure_costs(N, U, V, W); for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) { if (i > 0) { printf(" "); } printf("%lld",closure_costs[i]); } printf("\n"); return 0; } */

Compilation message (stderr)

roads.cpp: In function 'int dfs(int, int)':
roads.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for(auto [i, w]: adj[s]){
      |              ^
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:64:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |         for(auto [u, v, w]: edge[i]){
      |                  ^
#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...