Task: | Chain Reaction |
Sender: | aalto2024m_002 |
Submission time: | 2024-11-25 16:36:14 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.01 s | details |
#9 | ACCEPTED | 0.01 s | details |
#10 | ACCEPTED | 0.01 s | details |
#11 | ACCEPTED | 0.01 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | ACCEPTED | 0.09 s | details |
#14 | ACCEPTED | 0.06 s | details |
#15 | ACCEPTED | 0.08 s | details |
#16 | ACCEPTED | 0.09 s | details |
#17 | ACCEPTED | 0.10 s | details |
#18 | ACCEPTED | 0.01 s | details |
#19 | ACCEPTED | 0.01 s | details |
#20 | ACCEPTED | 0.01 s | details |
#21 | ACCEPTED | 0.01 s | details |
#22 | ACCEPTED | 0.01 s | details |
#23 | ACCEPTED | 0.08 s | details |
#24 | ACCEPTED | 0.09 s | details |
#25 | ACCEPTED | 0.08 s | details |
#26 | ACCEPTED | 0.09 s | details |
#27 | ACCEPTED | 0.09 s | details |
#28 | ACCEPTED | 0.08 s | details |
#29 | ACCEPTED | 0.09 s | details |
#30 | ACCEPTED | 0.08 s | details |
#31 | ACCEPTED | 0.09 s | details |
#32 | ACCEPTED | 0.08 s | details |
Code
#ifdef ONPC #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define char unsigned char #define rep(i, a, b) for(int i=a; i< (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define LSOne(S) ((S) & -(S)) using namespace std; // mt19937 rnd(239); mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); } typedef long double T; typedef complex<T> pt; #define X real() #define Y imag() template<class T> istream& operator>> (istream& is, complex<T>& p) { T value; is >> value; p.real(value); is >> value; p.imag(value); return is; } typedef long long ll; typedef long double ld; using pi = pair<ll, ll>; using vi = vector<ll>; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int popcnt(int x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef DEBUG #define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl; #else #define dbg(x...) #endif template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;} template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;} const int INF = 1e9; // 10^9 = 1B is < 2^31-1 const ll LLINF = 4e18; // 4*10^18 is < 2^63-1 const double EPS = 1e-9; const ll MOD = 1e9+7; const int N=1e5+10; ll res=1; ll a[N], b[N]; vector<int> adj[N]; void dfs(int node, int prev, ll curr) { chmax(res, curr); for(auto &w:adj[node]) { if(w==prev) continue; ll tmp=curr+max(a[w]-a[node], b[w]-b[node]); dfs(w, node, tmp); } } int solve() { int n, s; std::cin >> n >> s; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } for (int i = 1; i <= n; i++) { std::cin >> b[i]; } for (int i = 0; i < n-1; i++) { int u,v; std::cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs(s, -1, 1); std::cout << res << std::endl; return 0; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int TET = 1; //cin >> TET; for (int i = 1; i <= TET; i++) { #ifdef ONPC cout << "TEST CASE#" << i << endl; #endif if (solve()) { break; } #ifdef ONPC cout << "__________________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 1
4 2 1 1 1 5 2 1 5 4 1 2 1 3 ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 2
Verdict: ACCEPTED
input |
---|
4 1
4 2 2 1 1 1 1 1 1 2 2 3 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 3
Verdict: ACCEPTED
input |
---|
10 8
7 2 10 4 5 9 1 2 3 1 9 8 6 6 4 6 10 1 7 8 4 5 10 3 ... |
correct output |
---|
19 |
user output |
---|
19 |
Test 4
Verdict: ACCEPTED
input |
---|
10 1
8 8 6 8 1 9 2 2 7 7 9 6 5 9 2 5 6 5 5 8 1 6 6 7 ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 5
Verdict: ACCEPTED
input |
---|
10 1
4 1 4 1 4 6 1 1 4 5 5 9 3 9 8 8 10 8 7 10 3 1 1 9 ... |
correct output |
---|
11 |
user output |
---|
11 |
Test 6
Verdict: ACCEPTED
input |
---|
10 9
9 9 3 3 3 4 1 7 1 9 3 9 10 5 6 6 9 6 9 6 3 8 8 6 ... |
correct output |
---|
19 |
user output |
---|
19 |
Test 7
Verdict: ACCEPTED
input |
---|
10 1
3 4 2 2 2 10 1 5 10 3 10 8 7 6 2 10 1 6 1 3 2 3 10 4 ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 8
Verdict: ACCEPTED
input |
---|
10 10
80 58 90 31 79 35 10 75 83 70 48 2 25 73 99 7 53 79 36 89 9 4 7 9 ... |
correct output |
---|
54 |
user output |
---|
54 |
Test 9
Verdict: ACCEPTED
input |
---|
10 9
50 84 12 34 86 71 73 78 6 62 29 97 88 56 84 94 94 98 36 96 5 10 3 1 ... |
correct output |
---|
149 |
user output |
---|
149 |
Test 10
Verdict: ACCEPTED
input |
---|
10 5
7 66 89 87 27 80 2 11 29 3 98 7 52 66 21 2 26 19 96 31 4 6 1 10 ... |
correct output |
---|
226 |
user output |
---|
226 |
Test 11
Verdict: ACCEPTED
input |
---|
10 3
91 13 67 44 6 83 21 8 23 14 54 19 30 26 60 73 22 90 36 84 5 10 4 2 ... |
correct output |
---|
151 |
user output |
---|
151 |
Test 12
Verdict: ACCEPTED
input |
---|
10 5
87 61 47 96 50 23 35 54 26 87 16 60 77 75 77 91 59 16 23 51 5 1 10 8 ... |
correct output |
---|
175 |
user output |
---|
175 |
Test 13
Verdict: ACCEPTED
input |
---|
97304 87743
876894525 229121152 393060078 ... |
correct output |
---|
131459576065 |
user output |
---|
131459576065 |
Test 14
Verdict: ACCEPTED
input |
---|
74779 53246
763040787 482885163 932005790 ... |
correct output |
---|
155373737827 |
user output |
---|
155373737827 |
Test 15
Verdict: ACCEPTED
input |
---|
89537 85789
432185633 432110306 240073971 ... |
correct output |
---|
255801753825 |
user output |
---|
255801753825 |
Test 16
Verdict: ACCEPTED
input |
---|
99086 49261
283011093 775415197 945248913 ... |
correct output |
---|
162897193427 |
user output |
---|
162897193427 |
Test 17
Verdict: ACCEPTED
input |
---|
95142 68716
163121171 100246843 163249744 ... |
correct output |
---|
181966887510 |
user output |
---|
181966887510 |
Test 18
Verdict: ACCEPTED
input |
---|
19 3
49 73 32 44 84 29 9 76 77 36 9... |
correct output |
---|
147 |
user output |
---|
147 |
Test 19
Verdict: ACCEPTED
input |
---|
19 6
68 94 70 46 91 47 67 100 62 23... |
correct output |
---|
244 |
user output |
---|
244 |
Test 20
Verdict: ACCEPTED
input |
---|
18 3
90 65 90 80 41 5 95 17 53 7 29... |
correct output |
---|
127 |
user output |
---|
127 |
Test 21
Verdict: ACCEPTED
input |
---|
16 1
48 91 87 2 16 39 92 26 1 68 78... |
correct output |
---|
224 |
user output |
---|
224 |
Test 22
Verdict: ACCEPTED
input |
---|
15 2
11 1 37 1 8 20 24 59 42 52 91 ... |
correct output |
---|
219 |
user output |
---|
219 |
Test 23
Verdict: ACCEPTED
input |
---|
94171 47986
552466372 215830212 408722990 ... |
correct output |
---|
150760767335 |
user output |
---|
150760767335 |
Test 24
Verdict: ACCEPTED
input |
---|
94221 86537
45774448 992088337 309200563 7... |
correct output |
---|
105016024608 |
user output |
---|
105016024608 |
Test 25
Verdict: ACCEPTED
input |
---|
96867 68461
39428919 749383323 481367036 5... |
correct output |
---|
219609902823 |
user output |
---|
219609902823 |
Test 26
Verdict: ACCEPTED
input |
---|
96077 83268
95064821 23000135 276477667 48... |
correct output |
---|
140845793522 |
user output |
---|
140845793522 |
Test 27
Verdict: ACCEPTED
input |
---|
99950 74867
864529930 269063846 767129921 ... |
correct output |
---|
217758011647 |
user output |
---|
217758011647 |
Test 28
Verdict: ACCEPTED
input |
---|
97182 41080
671075894 704355936 662862756 ... |
correct output |
---|
167687874177 |
user output |
---|
167687874177 |
Test 29
Verdict: ACCEPTED
input |
---|
96113 18731
554071104 111523361 276689875 ... |
correct output |
---|
207695993751 |
user output |
---|
207695993751 |
Test 30
Verdict: ACCEPTED
input |
---|
92311 6858
440850686 890390689 572816739 ... |
correct output |
---|
150986466317 |
user output |
---|
150986466317 |
Test 31
Verdict: ACCEPTED
input |
---|
99999 25726
949775640 24729596 158203669 2... |
correct output |
---|
125772383324 |
user output |
---|
125772383324 |
Test 32
Verdict: ACCEPTED
input |
---|
97857 32129
20264277 670255203 316861628 1... |
correct output |
---|
182392362837 |
user output |
---|
182392362837 |