QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#611669#5418. Color the TreezqxWA 34ms29544kbC++232.2kb2024-10-04 22:02:492024-10-04 22:02:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 22:02:53]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:29544kb
  • [2024-10-04 22:02:49]
  • 提交

answer

#include<bits/stdc++.h>
#define AC return 0;
#define int long long 
#define pii pair<int,int>
#define all(tar) tar.begian(),tar.end()
const int maxx=2e5+5;
const int mod=998244353; 
using namespace std;
int n,m,t;
map<int,int>dp[maxx];
set<int>st[maxx];
int dep[maxx],a[maxx];
vector<int>G[maxx];
int minn[maxx],pos[maxx];
int anc[maxx][20];
int findfa(int x,int k){
   for(int i=0;i<20;i++){
      if(k&(1<<i))x=anc[x][i];
   }
   return x;
}
void dfs(int u,int fa){
   anc[u][0]=fa;
   dep[u]=dep[fa]+1;
   for(int i=1;(1<<i)<=dep[u];i++){
     anc[u][i]=anc[anc[u][i-1]][i-1];
   }
   int p=pos[dep[u]];
   int pa=findfa(u,p);
   st[pa].insert(dep[u]);
   dp[pa][dep[u]]=a[p];
   // cout<<u<<" "<<pa<<" "<<p<<'\n';
   for(auto v:G[u]){
      if(v==fa)continue;
      dfs(v,u);
      if(dp[u].size()>dp[v].size()){
      for(auto [x,y]:dp[v]){
         if(!st[u].count(x)){
            if(dp[u][x]+y>=a[x-dep[u]]){
               st[u].insert(x);
               dp[u][x]=a[x-dep[u]];
            }
            else dp[u][x]+=y;
         }
       }
      }else{
        auto f=dp[u];
        for(auto [x,y]:f){
          if(!st[u].count(x)){
            if(y+dp[v][x]>=a[x-dep[u]]){
               st[u].insert(x);
               dp[v][x]=a[x-dep[u]];
            }else{
               dp[v][x]+=y;
            } 
          }else dp[v][x]=y;
        }
        swap(dp[u],dp[v]);
      }
   }
   // cout<<u<<'\n';
   // for(auto [x,y]:dp[u])cout<<x<<" "<<y<<'\n';
}
signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   dep[0]=-1;
   cin>>t;
   while(t--){
      cin>>n;
      for(int i=1;i<=n;i++){
         dp[i].clear();
         G[i].clear();
         st[i].clear();
      }
      for(int i=0;i<n;i++)cin>>a[i];
      pos[0]=0,minn[0]=a[0];
      for(int i=1;i<n;i++){
         minn[i]=a[i];
         pos[i]=i;
         if(minn[i]>minn[i-1]){
            minn[i]=minn[i-1];
            pos[i]=pos[i-1];
         }
      }
      for(int i=1;i<n;i++){
         int u,v;
         cin>>u>>v;
         G[u].push_back(v);
         G[v].push_back(u);
      }
      dfs(1,0);
      int ans=0;
      for(auto [x,y]:dp[1])ans+=y;
      cout<<ans<<'\n';
   }
   AC
}   

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 29544kb

input:

3
4
10 15 40 1
1 2
2 3
2 4
5
10 5 1 100 1000
1 2
2 3
2 4
4 5
4
1000 200 10 8
1 2
2 3
3 4

output:

35
17
1218

result:

ok 3 number(s): "35 17 1218"

Test #2:

score: -100
Wrong Answer
time: 34ms
memory: 29292kb

input:

3000
54
43 44 11 49 17 14 7 30 35 12 34 14 15 8 29 47 30 31 39 17 26 23 26 45 34 50 49 13 35 18 29 15 13 44 47 5 22 20 19 46 30 22 26 13 47 46 43 27 48 48 13 14 30 44
1 2
1 3
2 4
3 5
4 6
2 7
4 8
1 9
3 10
1 11
8 12
2 13
9 14
1 15
1 16
15 17
15 18
7 19
1 20
19 21
13 22
10 23
17 24
9 25
9 26
24 27
8 28...

output:

180
179
222
230
156
240
225
126
100
81
155
73
154
127
149
124
234
230
132
187
162
170
90
282
195
358
206
211
119
197
211
233
88
252
239
236
173
180
195
133
109
148
180
175
226
210
182
97
245
59
56
31
115
248
218
172
139
208
53
140
189
187
173
137
233
94
163
273
80
350
156
133
146
159
240
271
137
225...

result:

wrong answer 2nd numbers differ - expected: '168', found: '179'