当前位置:网站首页>ZJNU 22-07-26 competition experience
ZJNU 22-07-26 competition experience
2022-07-27 20:15:00 【Fanshui 682】
detonation wa 11 rounds at the bottom (
It turned out that I even dfs You can't find the number of elements ( Data structure is learned in vain
ZJNU 22-07-26 - Virtual Judge (vjudge.net)
void dfs(int x){
siz[x]=1;
for (int i=0;i<ve[x].size();i++){
dfs(ve[x][i]);
siz[x]+=siz[ve[x][i]];
}
}routine dfs I can't think of the usage ..
F - No Link, Cut Tree!
The meaning of the title is complete binary tree , to n-1 Parent child chain and weight , Brightness is defined as the maximum value in the sum of the weights of the same depth , inquiry m Delete one node and all his children at a time , Ask the brightness after deletion .
Because the given chain is not given in order , So we should build a tree by the number of children's elements . Then maintain the suffix before , Just delete a point
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define pii pair<int,int>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define nep(i,r,l) for (int i=r;i>=l;i--)
#define CIO std::ios::sync_with_stdio(false)
using namespace std;
const int N=2e5+5;
int tr[N],pos[N];
int pre[30][N];
int tre[30][N];
int ans[N];
vector<int> ve[N];
int siz[N],dfn[N],val[N];
void dfs(int x){
siz[x]=1;
for (int i=0;i<ve[x].size();i++){
dfs(ve[x][i]);
siz[x]+=siz[ve[x][i]];
}
}
void DFS(int x,int idx){
dfn[idx]=x;
if (ve[x].size()==0) return;
else if (ve[x].size()==1){
DFS(ve[x][0],idx*2);
}
else{
if (siz[ve[x][0]]>siz[ve[x][1]]){
DFS(ve[x][0],idx*2);
DFS(ve[x][1],idx*2+1);
}
else{
DFS(ve[x][0],idx*2+1);
DFS(ve[x][1],idx*2);
}
}
}
void work(){
int n,m,w1;
cin>>n>>m>>w1;
tr[1]=w1;dfn[1]=1;
int u,v,w;
rep(i,2,n){
cin>>u>>v>>w;
ve[v].push_back(u);
val[u]=w;
}
dfs(1);
DFS(1,1);
rep(i,1,n){
tr[i]=val[dfn[i]];
pos[dfn[i]]=i;
}
tr[1]=w1;
for (int i=0;(1<<i)<=n;i++){
for (int j=(1<<i);j<=((1<<(i+1))-1);j++){
pre[i][j]=pre[i][j-1]+tr[j];
}
}
for (int i=0;(1<<i)<=n;i++){
for (int j=(1<<(i+1))-1;j>=(1<<i);j--){
tre[i][j]=tre[i][j+1]+tr[j];
}
}
rep(i,1,m){
cin>>u;
if (ans[u]!=0){cout<<ans[u]<<endl;continue;}
if (u==1){cout<<0<<endl;continue;}
int c=0;
int base=1;
while (pos[u]>=base){
base=base*2;
c++;
}
base=base/2;
c--;
int l,r;
int sum=w1;
l=r=pos[u];
int cnt=0;
int b=1;
while (b<base){
cnt++;
sum=max(sum,pre[cnt-1][b*2-1]);
b=b*2;
}
while ((1<<cnt)<=n){
sum=max(sum,pre[cnt][l-1]+tre[cnt][r+1]);
l=l*2;
r=r*2+1;
cnt++;
}
ans[u]=sum;
cout<<sum<<endl;
}
}
signed main(){
CIO;
{
work();
}
return 0;
}
G - Hungry Canadian
Not at all dp..
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define pii pair<int,int>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define nep(i,r,l) for (int i=r;i>=l;i--)
#define CIO std::ios::sync_with_stdio(false)
using namespace std;
const int N=2e5+5;
int p[30][30];
int dp[N][30];
void work(){
int k;cin>>k;
rep(i,1,26){
rep(j,1,26){
cin>>p[i][j];
}
}
memset(dp,0x3f,sizeof dp);
for (int i=1;i<=26;i++) dp[1][i]=0;
for (int i=1;i<=k;i++){
for (int j=1;j<=26;j++){
for (int l=1;l<=26;l++){
dp[i][j]=min(dp[i][j],dp[i-1][l]+p[l][j]);
}
}
}
int ans=INT_MAX;
for (int i=1;i<=26;i++){
ans=min(ans,dp[k][i]);
}
cout<<ans<<endl;
}
signed main(){
CIO;
//int _;cin>>_;while(_--)
{
work();
}
return 0;
}
边栏推荐
- 如何快速提升抖音小店三分钟回复率?哪些情况会影响抖音小店回复率呢?
- Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)
- LG集团宣布将向湖北捐赠300万元现金、120万个口罩、1万套防护服
- [redis] several deployment methods of redis
- Solve the problem of displaying the scroll bar when there is no data in the viewui table
- 什么是多层感知机(什么是多层感知机)
- Software configuration | tigervnc download, installation and configuration
- 解决 ViewUI 表格无数据时展示滚动条的问题
- 京东:获得商品详情原数据 API
- shell
猜你喜欢

信道容量、信道带宽基本概念的理解

YY English learning about fish
![[论文阅读] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation](/img/a9/690f52b5c4afba684f0add2434888c.png)
[论文阅读] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation

Product Manager: check where there is an error prompt of "system exception" on the offline

产品经理:排查下线上哪里冒出个“系统异常”的错误提示

Underlying principle of mvcc

长安链数据存储源码分析

Talk about how redis handles requests

Introduction to basic cesium controls

antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key
随机推荐
如何快速提升抖音小店三分钟回复率?哪些情况会影响抖音小店回复率呢?
[论文阅读] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation
An in-depth understanding of crystal oscillation circuit derived from xtalin pin and xtalout pin of single chip microcomputer
Software configuration | tigervnc download, installation and configuration
Huawei's mobile phone shipments exceed Apple's, ranking second in the world, but it faces a large amount of inventory that needs to be cleaned up
Source code analysis of Chang'an chain data storage
Acwing 692. g bus count difference + prefix and
If you want to switch to software testing, you should pass these three tests first, including a 3000 word super full test learning guide
传英特尔将停掉台积电16nm代工的Nervana芯片
C # network application programming, experiment 1: WPF exercise
Datepicker date selector in viewui compatible solution in ie11 browser
What does bus mean
TS2532: Object is possibly ‘undefined‘
Libpcap library and pcap_ Sendpacket interface function understanding
图解LeetCode——592. 分数加减运算(难度:中等)
最新获得淘宝app商品详情原数据 的API
调整数组使奇数全部都位于偶数前
How to encrypt the data in MySQL database? Mysql8.0 comes with new features
内置函数时间日期函数
PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)