QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#310082 | #8138. Alice and Her Lost Cat | bachbeo2007 | AC ✓ | 19ms | 65788kb | C++23 | 3.3kb | 2024-01-21 01:22:44 | 2024-01-21 01:22:45 |
Judging History
answer
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=2005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
const int base=101;
int n,a[maxn],t[maxn],sz[maxn];
int dp[maxn][maxn][2];
vector<int> edge[maxn];
int cur[maxn][2],tmp[maxn],G[maxn];
void dfs(int u,int p){
int sum=0;sz[u]=0;
for(int v:edge[u]){
if(v==p) continue;
dfs(v,u);sum+=sz[v];
}
if(!sum){
sz[u]=1;
dp[u][1][1]=0;
dp[u][1][0]=0;
dp[u][0][1]=0;
dp[u][0][0]=a[u];
return;
}
for(int i=0;i<=sum;i++) dp[u][i][0]=dp[u][i][1]=G[i]=inf;
dp[u][0][0]=dp[u][0][1]=G[0]=0;
for(int v:edge[u]){
if(v==p) continue;
for(int i=0;i<=sz[u]+sz[v];i++) cur[i][0]=cur[i][1]=tmp[i]=inf;
for(int i=0;i<=sz[u];i++) for(int j=0;j<=sz[v];j++){
for(int a=0;a<=1;a++) for(int b=0;b<=1-a;b++) cur[i+j][a+b]=min(cur[i+j][a+b],dp[u][i][a]+dp[v][j][b]);
tmp[i+j]=min(tmp[i+j],G[i]+dp[v][j][1]);
}
sz[u]+=sz[v];
for(int i=0;i<=sz[u];i++){
G[i]=tmp[i];
dp[u][i][0]=cur[i][0];
dp[u][i][1]=cur[i][1];
}
}
for(int i=0;i<=sz[u];i++){
dp[u][i][0]=min(dp[u][i][0],G[i]+a[u]);
dp[u][i][1]=min(dp[u][i][1],dp[u][i][0]);
}
}
void solve(){
cin >> n;
for(int i=1;i<=n;i++) edge[i].clear();
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) cin >> t[i];
for(int i=1;i<n;i++){
int u,v;cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
dfs(1,0);
int ans=inf;
for(int i=0;i<=sz[1];i++) ans=min(ans,dp[1][i][1]+t[i]);
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;cin >> test;
while(test--) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5800kb
input:
2 8 4 2 5 2 4 2 3 2 5 5 6 7 8 9 10 13 1 2 2 3 1 4 1 5 4 6 3 7 5 8 8 4 2 3 3 2 4 4 3 4 6 8 8 9 9 14 17 1 2 2 3 3 4 3 5 4 6 3 7 3 8
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
3 1 10 5 3 2 1 4 1 2 3 1 2 2 3 10 2 1 4 3 5 6 7 8 9 3 1 1 2 3 4 5 6 7 8 8 1 2 2 3 1 4 1 5 5 6 4 7 1 8 1 9 7 10
output:
0 0 2
result:
ok 3 number(s): "0 0 2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
5 10 1 1 3 4 4 2 3 3 3 1 4 4 7 9 17 17 19 19 19 20 1 2 2 3 1 4 2 5 1 6 3 7 1 8 2 9 2 10 10 2 3 3 3 4 1 3 3 1 3 2 4 5 6 9 10 12 15 19 20 1 2 2 3 2 4 1 5 5 6 6 7 7 8 1 9 5 10 10 3 3 3 3 3 3 1 4 2 3 1 4 10 10 14 15 16 17 18 20 1 2 1 3 3 4 1 5 2 6 4 7 6 8 2 9 3 10 10 1 2 1 3 2 3 1 2 1 2 1 1 2 3 4 5 9 9 ...
output:
2 5 5 2 2
result:
ok 5 number(s): "2 5 5 2 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
5 20 3 5 1 1 3 4 7 8 3 7 1 1 7 1 3 3 5 1 5 7 1 14 25 27 30 34 39 42 45 48 50 50 55 61 63 69 74 87 89 100 1 2 1 3 3 4 1 5 2 6 6 7 6 8 1 9 7 10 5 11 7 12 7 13 12 14 12 15 1 16 5 17 4 18 9 19 2 20 20 3 8 2 4 7 6 1 1 2 2 7 5 1 1 2 6 4 5 7 1 2 10 24 25 26 28 28 37 47 47 52 64 79 80 84 86 90 93 96 100 1 2...
output:
10 9 17 11 9
result:
ok 5 number(s): "10 9 17 11 9"
Test #5:
score: 0
Accepted
time: 10ms
memory: 59468kb
input:
10 1400 9827328 3447883 6979832 2361516 3201742 9881490 185103 6613510 7140147 9824105 7999173 649272 9056196 6021519 9367368 8153964 9840232 5449142 8119900 4715774 987231 1057668 5380695 9747965 2253752 1322003 2341542 2845358 5610842 8241778 4692550 7564041 2602876 4842402 3872716 3869113 7268396...
output:
342781747 371288274 187920801 21955588 250360535 236318821 224802283 390524828 281444264 291421823
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 61376kb
input:
10 453 5186175 1420962 8950921 3420584 8352122 1606964 3615305 1662335 7129112 3853538 6275884 9171435 3518623 3492528 7692505 896099 815548 2768295 8173599 7502498 2580478 8521940 1367535 3474343 5647192 5476807 9769184 4719283 7538595 7137045 9438506 1272015 1397402 2647766 1270571 1122883 2075228...
output:
206244715 341230840 244108106 365394739 358176901 115691440 169329823 18005551 319842026 69815045
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 12ms
memory: 65472kb
input:
10 1505 6803198 9426809 954777 705060 3502503 3299671 7078275 6678392 7118077 4206683 8294418 7660830 1788411 930769 6017642 7380058 8049040 152984 8227298 321991 4173725 2309924 7387143 942545 2815224 3406202 7196826 6560441 9466349 6032311 4184462 4947221 3868216 6711306 8701195 4602061 623884 797...
output:
361208793 43741741 261474287 336596228 308022071 311882982 354011854 278470501 88889642 332327962
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 19ms
memory: 65672kb
input:
10 2000 3006604 5311265 2859626 3609818 8193678 7844282 2223127 7294340 1308287 6762790 88400 7428240 18325 6641350 8972559 2660020 9868202 7449155 8047535 5532457 6643387 6091653 3134704 500907 6052842 9516604 8558965 1950203 3278845 9863131 9361606 5492957 9812317 7335192 339790 4364441 4093591 98...
output:
377336374 388737941 381821708 333910519 360165603 344789836 391740730 364782918 385405245 382161455
result:
ok 10 numbers
Test #9:
score: 0
Accepted
time: 11ms
memory: 58596kb
input:
10 2000 3115656 6928288 865473 5613675 5510922 2994662 3948601 4466366 66168 6718986 4150601 5672183 4765896 1103778 6410800 1017925 6384929 4715414 5432225 5553388 9495648 7684900 6889920 2778691 9811988 2975580 2779304 9377845 5152771 1823653 1998696 238912 9745699 9838775 8145154 1762297 1314593 ...
output:
330389721 372008389 369537673 368481583 364593955 355194354 347294289 366850614 363318922 379964359
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 11ms
memory: 63908kb
input:
10 2000 3224709 2287136 8838552 7584764 6537222 8145042 5608539 7896568 5114994 6740719 4470978 7657949 3288059 5631742 3849042 9343062 9127064 5690730 2751378 5607087 2315141 9212611 645136 8765531 3505598 6369021 675932 6805487 768520 3751407 893963 4984868 3453673 8567765 2208694 5451097 8535594 ...
output:
406240490 396273822 373075313 373215271 366225425 372414756 349190757 388338626 357010416 385577925
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 16ms
memory: 65788kb
input:
10 2000 3333761 3904159 3069807 5846797 3854466 3295422 1075837 1359538 131051 6729684 8533179 5934660 8068398 3835993 7578227 7668199 5611024 2924221 136067 5693554 5134633 805858 8109408 4785139 941032 3504285 4863504 4233129 2609678 5711928 9854766 3472648 7128879 1104115 14057 2848952 2047540 28...
output:
351661825 367417601 363942333 380444399 377825080 363473980 361578810 379150119 338648231 364417836
result:
ok 10 numbers
Extra Test:
score: 0
Extra Test Passed