当前位置:网站首页>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;
}
边栏推荐
- Datepicker date selector in viewui compatible solution in ie11 browser
- TS2532: Object is possibly ‘undefined‘
- 想转行软件测试,先过这三关,包含一份3000字超全测试学习指南
- 《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24
- 办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案
- LeetCode练习2——两数之和
- Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)
- 邬贺铨:因地制宜 数字化技术赋能“双碳”实践
- Codeforces Round #810 (Div. 2)B.party(思维题)超详细题解
- 汇顶科技:收购恩智浦VAS业务已完成交割
猜你喜欢

How to encrypt the data in MySQL database? Mysql8.0 comes with new features

PMP每日一练 | 考试不迷路-7.27(包含敏捷+多选)

办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案

Use cpolar to build a business website (5)

《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24

MVCC的底层原理

一看就懂的ESLint

邬贺铨:因地制宜 数字化技术赋能“双碳”实践

总线Bus是什么意思

Datepicker date selector in viewui compatible solution in ie11 browser
随机推荐
西数移动硬盘无法读取(高枕无忧的成语)
函数优先顺序
预处理与宏定义
继华为、联发科之后,这家手机芯片厂商宣布向武汉捐款700万
华为手机出货超苹果成全球第二,但面临大量库存需要清理
An in-depth understanding of crystal oscillation circuit derived from xtalin pin and xtalout pin of single chip microcomputer
Qtexttospeech class of QT realizes voice broadcast function
[Redis] Redis穿透、雪崩和击穿
uva1421
最新获得淘宝app商品详情原数据 的API
Ms721 load test
If you want to switch to software testing, you should pass these three tests first, including a 3000 word super full test learning guide
使用cpolar建立一个商业网站(5)
C170: retest screening
C background GC cause and effect
联发科发布中端游戏手机芯片Helio G80
一看就懂的ESLint
Function priority
产品经理:排查下线上哪里冒出个“系统异常”的错误提示
Online judge output overrun