Submission #737599

#TimeUsernameProblemLanguageResultExecution timeMemory
737599Ronin13Firefighting (NOI20_firefighting)C++14
Compilation error
0 ms0 KiB
include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 300001; vector <vector <pll> > g(nmax); int p[nmax][22]; ll d[nmax][22]; //ll len[nmax][22]; ll dp[nmax]; vector <vector <pll> > cent(nmax); vector <ll> cur(nmax); void dfs(int v, int e, ll last){ p[v][0] = e; d[v][0] = last; for(int j = 1; j <= 20; j++){ p[v][j] = p[p[v][j - 1]][j - 1]; d[v][j] = d[v][j - 1] + d[p[v][j - 1]][j - 1]; } for(auto x : g[v]){ int to = x.f; if(to == e) continue; dp[to] = dp[v] + x.s; dfs(to, v, x.s); } } ll getlast(int v, ll k){ for(int j = 20; j >= 0; j--){ if(d[v][j] > k) continue; k -= d[v][j]; v = p[v][j]; } return v; } vector <int> sz(nmax); vector <bool> marked(nmax); void DFS(int v, int e){ sz[v] = 1; for(auto ed : g[v]){ int to = ed.f; if(to == e) continue; if(marked[to]) continue; DFS(to, v); sz[v] += sz[to]; } } int find_cen(int v, int e, int n){ for(auto ed : g[v]){ int to = ed.f; if(to == e) continue; if(marked[to]) continue; if(sz[to] > n / 2){ return find_cen(to, v, n); } } return v; } void DFS2(int v, int e, int lead, ll cur){ cent[v].pb({lead, cur}); for(auto x : g[v]){ int to = x.f; if(to == e) continue; if(marked[to]) continue; DFS2(to, v, lead, cur + x.s); } } void upd(int v){ for(auto to : cent[v]){ cur[to.f] = min(cur[to.f], to.s); } } ll getans(int v){ ll mn = 1e18; for(auto to : cent[v]){ mn = min(mn, cur[to.f] + to.s); } return mn; } void decompose(int v){ DFS(v, v); int x = find_cen(v, v, sz[v]); DFS2(x, x, x, 0); marked[x] = true; for(auto ed : g[x]){ int to = ed.f; if(marked[to]) continue; decompose(to); } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n; cin >> n; ll k; cin >> k; for(int i = 1; i < n; i++){ int u, v; cin >> u >> v; ll w; cin >> w; g[u].pb({v, w}); g[v].pb({u, w}); } for(int j= 0; j < 20; j++){ d[0][j] = 1e12; } dfs(1, 1, 0); decompose(1); vector <pll> vec; for(int i= 1;i <= n; i++){ vec.pb({dp[i], i}); } sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); int cnt = 0; vector <int> ans; for(int i = 1; i <= n; i++){ cur[i] = 1e18; } for(auto x : vec){ int to = x.s; ll o = getans(to); if(o <= k){ continue; } cnt++; int v = getlast(to, k); upd(v); ans.pb(v); } cout << cnt << "\n"; for(int to : ans){ cout<< to << ' '; } return 0; }

Compilation message (stderr)

Firefighting.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
Firefighting.cpp:12:1: error: 'vector' does not name a type
   12 | vector <vector <pll> > g(nmax);
      | ^~~~~~
Firefighting.cpp:17:1: error: 'vector' does not name a type
   17 | vector <vector <pll> > cent(nmax);
      | ^~~~~~
Firefighting.cpp:18:1: error: 'vector' does not name a type
   18 | vector <ll> cur(nmax);
      | ^~~~~~
Firefighting.cpp: In function 'void dfs(int, int, long long int)':
Firefighting.cpp:27:18: error: 'g' was not declared in this scope
   27 |     for(auto x : g[v]){
      |                  ^
Firefighting.cpp: At global scope:
Firefighting.cpp:44:1: error: 'vector' does not name a type
   44 | vector <int> sz(nmax);
      | ^~~~~~
Firefighting.cpp:45:1: error: 'vector' does not name a type
   45 | vector <bool> marked(nmax);
      | ^~~~~~
Firefighting.cpp: In function 'void DFS(int, int)':
Firefighting.cpp:48:5: error: 'sz' was not declared in this scope; did you mean 's'?
   48 |     sz[v] = 1;
      |     ^~
      |     s
Firefighting.cpp:49:19: error: 'g' was not declared in this scope
   49 |     for(auto ed : g[v]){
      |                   ^
Firefighting.cpp:52:12: error: 'marked' was not declared in this scope
   52 |         if(marked[to]) continue;
      |            ^~~~~~
Firefighting.cpp: In function 'int find_cen(int, int, int)':
Firefighting.cpp:60:19: error: 'g' was not declared in this scope
   60 |     for(auto ed : g[v]){
      |                   ^
Firefighting.cpp:63:12: error: 'marked' was not declared in this scope
   63 |         if(marked[to]) continue;
      |            ^~~~~~
Firefighting.cpp:64:12: error: 'sz' was not declared in this scope; did you mean 's'?
   64 |         if(sz[to] > n / 2){
      |            ^~
      |            s
Firefighting.cpp: In function 'void DFS2(int, int, int, long long int)':
Firefighting.cpp:73:5: error: 'cent' was not declared in this scope
   73 |     cent[v].pb({lead, cur});
      |     ^~~~
Firefighting.cpp:74:18: error: 'g' was not declared in this scope
   74 |     for(auto x : g[v]){
      |                  ^
Firefighting.cpp:77:12: error: 'marked' was not declared in this scope
   77 |         if(marked[to]) continue;
      |            ^~~~~~
Firefighting.cpp: In function 'void upd(int)':
Firefighting.cpp:83:19: error: 'cent' was not declared in this scope
   83 |     for(auto to : cent[v]){
      |                   ^~~~
Firefighting.cpp:84:9: error: 'cur' was not declared in this scope
   84 |         cur[to.f] = min(cur[to.f], to.s);
      |         ^~~
Firefighting.cpp:84:21: error: 'min' was not declared in this scope
   84 |         cur[to.f] = min(cur[to.f], to.s);
      |                     ^~~
Firefighting.cpp: In function 'long long int getans(int)':
Firefighting.cpp:90:19: error: 'cent' was not declared in this scope
   90 |     for(auto to : cent[v]){
      |                   ^~~~
Firefighting.cpp:91:22: error: 'cur' was not declared in this scope
   91 |         mn = min(mn, cur[to.f] + to.s);
      |                      ^~~
Firefighting.cpp:91:14: error: 'min' was not declared in this scope; did you mean 'mn'?
   91 |         mn = min(mn, cur[to.f] + to.s);
      |              ^~~
      |              mn
Firefighting.cpp: In function 'void decompose(int)':
Firefighting.cpp:98:28: error: 'sz' was not declared in this scope; did you mean 's'?
   98 |     int x = find_cen(v, v, sz[v]);
      |                            ^~
      |                            s
Firefighting.cpp:100:5: error: 'marked' was not declared in this scope
  100 |     marked[x] = true;
      |     ^~~~~~
Firefighting.cpp:101:19: error: 'g' was not declared in this scope
  101 |     for(auto ed : g[x]){
      |                   ^
Firefighting.cpp: In function 'int main()':
Firefighting.cpp:109:3: error: 'ios_base' has not been declared
  109 |   ios_base::sync_with_stdio(false);cin.tie(0);
      |   ^~~~~~~~
Firefighting.cpp:109:36: error: 'cin' was not declared in this scope
  109 |   ios_base::sync_with_stdio(false);cin.tie(0);
      |                                    ^~~
Firefighting.cpp:115:9: error: 'g' was not declared in this scope
  115 |         g[u].pb({v, w});
      |         ^
Firefighting.cpp:124:5: error: 'vector' was not declared in this scope
  124 |     vector <pll> vec;
      |     ^~~~~~
Firefighting.cpp:7:13: error: 'pair' was not declared in this scope
    7 | #define pll pair<ll,ll>
      |             ^~~~
Firefighting.cpp:124:13: note: in expansion of macro 'pll'
  124 |     vector <pll> vec;
      |             ^~~
Firefighting.cpp:2:12: error: expected primary-expression before 'long'
    2 | #define ll long long
      |            ^~~~
Firefighting.cpp:7:18: note: in expansion of macro 'll'
    7 | #define pll pair<ll,ll>
      |                  ^~
Firefighting.cpp:124:13: note: in expansion of macro 'pll'
  124 |     vector <pll> vec;
      |             ^~~
Firefighting.cpp:126:9: error: 'vec' was not declared in this scope
  126 |         vec.pb({dp[i], i});
      |         ^~~
Firefighting.cpp:128:10: error: 'vec' was not declared in this scope
  128 |     sort(vec.begin(), vec.end());
      |          ^~~
Firefighting.cpp:128:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  128 |     sort(vec.begin(), vec.end());
      |     ^~~~
      |     short
Firefighting.cpp:129:5: error: 'reverse' was not declared in this scope
  129 |     reverse(vec.begin(), vec.end());
      |     ^~~~~~~
Firefighting.cpp:131:13: error: expected primary-expression before 'int'
  131 |     vector <int> ans;
      |             ^~~
Firefighting.cpp:133:9: error: 'cur' was not declared in this scope
  133 |         cur[i] = 1e18;
      |         ^~~
Firefighting.cpp:144:9: error: 'ans' was not declared in this scope
  144 |         ans.pb(v);
      |         ^~~
Firefighting.cpp:146:5: error: 'cout' was not declared in this scope
  146 |     cout << cnt << "\n";
      |     ^~~~
Firefighting.cpp:147:18: error: 'ans' was not declared in this scope
  147 |     for(int to : ans){
      |                  ^~~