Compile Error
foo.cc:1:2: error: expected unqualified-id before '<' token 1 | <bits/stdc++.h> | ^ foo.cc:25:13: error: 'pair' does not name a type 25 | using pii = pair<int, int>; | ^~~~ foo.cc:26:13: error: 'pair' does not name a type 26 | using pdd = pair<double, double>; | ^~~~ foo.cc:27:13: error: 'pair' does not name a type 27 | using pbb = pair<bool, bool>; | ^~~~ foo.cc:28:13: error: 'pair' does not name a type 28 | using pcc = pair<char, char>; | ^~~~ foo.cc:29:13: error: 'pair' does not name a type 29 | using pss = pair<string, string>; | ^~~~ foo.cc:30:12: error: 'vector' does not name a type 30 | using vi = vector<int>; | ^~~~~~ foo.cc:31:12: error: 'vector' does not name a type 31 | using vd = vector<double>; | ^~~~~~ foo.cc:32:12: error: 'vector' does not name a type 32 | using vb = vector<bool>; | ^~~~~~ foo.cc:33:12: error: 'vector' does not name a type 33 | using vc = vector<char>; | ^~~~~~ foo.cc:34:12: error: 'vector' does not name a type 34 | using vs = vector<string>; | ^~~~~~ foo.cc:35:14: error: 'vector' does not name a type 35 | using vpii = vector<pair<int, int>>; | ^~~~~~ foo.cc:36:14: error: 'vector' does not name a type 36 | using vpdd = vector<pair<double, double>>; | ^~~~~~ foo.cc:37:14: error: 'vector' does not name a type 37 | using vpbb = vector<pair<bool, bool>>; | ^~~~~~ foo.cc:38:14: error: 'vector' does not name a type 38 | using vpcc = vector<pair<char, char>>; | ^~~~~~ foo.cc:39:14: error: 'vector' does not name a type 39 | using vpss = vector<pair<string, string>>; | ^~~~~~ foo.cc:40:13: error: 'vector' does not name a type 40 | using vvi = vector<vector<int>>; | ^~~~~~ foo.cc:41:13: error: 'vector' does not name a type 41 | using vvd = vector<vector<double>>; | ^~~~~~ foo.cc:42:13: error: 'vector' does not name a type 42 | using vvb = vector<vector<bool>>; | ^~~~~~ foo.cc:43:13: error: 'vector' does not name a type 43 | using vvc = vector<vector<char>>; | ^~~~~~ foo.cc:44:13: error: 'vector' does not name a type 44 | using vvs = vector<vector<string>>; | ^~~~~~ foo.cc:45:15: error: 'vector' does not name a type 45 | using vvpii = vector<vector<pair<int, int>>>; | ^~~~~~ foo.cc:46:15: error: 'vector' does not name a type 46 | using vvpdd = vector<vector<pair<double, double>>>; | ^~~~~~ foo.cc:47:15: error: 'vector' does not name a type 47 | using vvpbb = vector<vector<pair<bool, bool>>>; | ^~~~~~ foo.cc:48:15: error: 'vector' does not name a type 48 | using vvpcc = vector<vector<pair<char, char>>>; | ^~~~~~ foo.cc:49:15: error: 'vector' does not name a type 49 | using vvpss = vector<vector<pair<string, string>>>; | ^~~~~~ foo.cc:52:31: error: 'priority_queue' does not name a type 52 | template <class T> using pq = priority_queue<T>; | ^~~~~~~~~~~~~~ foo.cc:53:32: error: 'priority_queue' does not name a type 53 | template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; | ^~~~~~~~~~~~~~ foo.cc:63:10: error: 'uint64_t' does not name a type 63 | static uint64_t splitmix64(uint64_t x) { | ^~~~~~~~ foo.cc:1:1: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'? +++ |+#include <cstdint> 1 | <bits/stdc++.h> foo.cc:71:3: error: 'size_t' does not name a type 71 | size_t operator()(uint64_t x) const { | ^~~~~~ foo.cc:1:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'? +++ |+#include <cstddef> 1 | <bits/stdc++.h> foo.cc: In function 'void solve()': foo.cc:80:3: error: 'cin' was not declared in this scope 80 | cin >> n >> k; | ^~~ foo.cc:81:3: error: 'vi' was not declared in this scope 81 | vi a(n + 1); | ^~ foo.cc:83:12: error: 'a' was not declared in this scope 83 | cin >> a[i]; | ^ foo.cc:86:3: error: 'unordered_map' was not declared in this scope 86 | unordered_map<int, vi, custom_hash> adj; | ^~~~~~~~~~~~~ foo.cc:12:13: error: expected primary-expression before 'long' 12 | #define int long long | ^~~~ foo.cc:86:17: note: in expansion of macro 'int' 86 | unordered_map<int, vi, custom_hash> adj; | ^~~ foo.cc:91:5: error: 'adj' was not declared in this scope 91 | adj[u].eb(v); | ^~~ foo.cc:95:3: error: 'queue' was not declared in this scope 95 | queue<tuple<int, int, int, int>> q; | ^~~~~ foo.cc:95:9: error: 'tuple' was not declared in this scope 95 | queue<tuple<int, int, int, int>> q; | ^~~~~ foo.cc:12:13: error: expected primary-expression before 'long' 12 | #define int long long | ^~~~ foo.cc:95:15: note: in expansion of macro 'int' 95 | queue<tuple<int, int, int, int>> q; | ^~~ foo.cc:100:5: error: 'q' was not declared in this scope 100 | q.push({i, -1, 1, a[i]}); | ^ foo.cc:100:23: error: 'a' was not declared in this scope 100 | q.push({i, -1, 1, a[i]}); | ^ foo.cc:105:13: error: 'max' was not declared in this scope 105 | ans = max(ans, sum); | ^~~ foo.cc:111:31: error: 'adj' was not declared in this scope 111 | for (const int &child : adj[node]) { | ^~~ foo.cc:120:3: error: 'cout' was not declared in this scope 120 | cout << ans << '\n'; | ^~~~ foo.cc: In function 'int main()': foo.cc:126:3: error: 'ios' has not been declared 126 | ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); | ^~~ foo.cc:126:28: error: 'cin' was not declared in this scope 126 | ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); | ^~~ foo.cc:126:40: error: 'cout' was not declared in this scope 126 | ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); | ^~~~
Code
<bits/stdc++.h>
// #ifndef ONLINE_JUDGE
// #include "template.cpp"
// #else
// #define debug(...)
// #define debugArr(...)
// #endif
#define F first
#define S second
#define int long long
#define double long double
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define mp(x, y) make_pair(x, y)
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define INF (int)1e18
using namespace std;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pbb = pair<bool, bool>;
using pcc = pair<char, char>;
using pss = pair<string, string>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpdd = vector<pair<double, double>>;
using vpbb = vector<pair<bool, bool>>;
using vpcc = vector<pair<char, char>>;
using vpss = vector<pair<string, string>>;
using vvi = vector<vector<int>>;
using vvd = vector<vector<double>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvpii = vector<vector<pair<int, int>>>;
using vvpdd = vector<vector<pair<double, double>>>;
using vvpbb = vector<vector<pair<bool, bool>>>;
using vvpcc = vector<vector<pair<char, char>>>;
using vvpss = vector<vector<pair<string, string>>>;
// clang-format off
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> T sqrt_(T elem) {int l=1,r=elem;while(l<=r){int mid=l+(r-l)/2LL;if(mid>elem/mid){r=mid-1;}else{int val=mid*mid;if(val<=elem){l=mid+1;}else{r=mid-1;}}}return r;}
template <class T> T ceil_(T a,T b) {return(a+b-1)/b;};
template <class T> T mod_add(T a,T b,T mod){return((a%mod)+(b%mod))% mod;}
template <class T> T mod_sub(T a,T b,T mod){return((a%mod)-(b%mod)+mod)%mod;}
template <class T> T mod_mul(T a,T b,T mod){return((a%mod)*(b%mod))%mod;}
template <class T> T mod_inv(T a,T mod){T m0=mod,y=0,x=1;if(mod==1)return 0;while(a>1){T q=a/mod;T t=mod;mod=a%mod,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}
template <class T> T mod_div(T a,T b,T mod){return mod_mul(a,mod_inv(b,mod),mod);}
// clang-format on
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
void solve() {
int n, k;
cin >> n >> k;
vi a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
unordered_map<int, vi, custom_hash> adj;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].eb(v);
adj[v].eb(u);
}
queue<tuple<int, int, int, int>> q;
int ans = 0;
// node, par, dis;
for (int i = 1; i <= n; i++) {
q.push({i, -1, 1, a[i]});
while (!q.empty()) {
auto [node, par, dis, sum] = q.front();
q.pop();
ans = max(ans, sum);
if (dis >= k) {
continue;
}
for (const int &child : adj[node]) {
if (child != par) {
if (dis + 1 <= k) {
q.push({child, node, dis + 1, sum + a[child]});
}
}
}
}
}
cout << ans << '\n';
return;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tt = 1, count = 1;
// cin >> tt;
while (tt--) {
// cout << "Case #" << count << ": ";
solve();
++count;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1160 Max path sum (Easy Version)
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-04-06 15:15:02
- Judged At
- 2025-04-06 15:15:02
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes