E. Tree Painting(换根)

#include <iostream>
#include <vector>
#include <cstring>
#define ll long long
using namespace std;
vector<int> g[1008611];
int v;
int n,siz[1008611];
ll up[1008611], sum[1008611];
void init(int u,int f) {
    siz[u]=1;
    for(auto v:g[u]) {
        if(v==f) continue;
        init(v,u);
        siz[u] += siz[v];
        sum[u] += sum[v] + siz[v];
    }
}
void dfs(int u,int f,int root) {
    if (f != u) {
          up[u] = up[f] + siz[root] + sum[f] - sum[u] - 2*siz[u];
    }
    for(auto v: g[u]) {
        if(v==f) continue;
        dfs(v,u,root);
    }
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        g[i].clear();
    }
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1,1);
    dfs(1,1,1);
    ll ans = 0;
    for(int i=1;i<=n;i++)
        ans=max(ans,up[i]+sum[i]);
    cout <<ans+n<< endl;
    return 0;
}

 

### 使用 DeepSeek 实现 AI 绘画的方法 #### 准备工作 为了顺利使用DeepSeek进行AI绘画,需要先安装并配置好环境。确保计算机满足最低硬件要求,并按照官方文档完成软件包的下载与安装[^1]。 #### 创建项目结构 建立一个新的文件夹作为项目的目录,在此内部创建子文件用于存储图像数据集、预训练模型权重以及自定义脚本等资源文件。 ```bash mkdir deepseek_ai_painting && cd $_ tree . . ├── data/ │ └── input_images/ # 用户上传或指定的艺术风格样本图片路径 └── models/ └── pretrained_weights.h5 # 预训练好的神经网络参数保存位置 ``` #### 加载预处理模块 编写Python脚本来加载必要的库和初始化DeepSeek实例对象。这里假设已经成功导入了`deepseek`库: ```python import deepseek as ds # 初始化DeepSeek客户端连接 client = ds.Client(api_key='your_api_key_here') ``` #### 设定提示词生成逻辑 据具体应用场景定制化设置关键词提取算法或者直接提供固定模板供用户选择。例如针对动漫头像创作可以采用如下方式获取描述信息: ```python def get_prompt(description): """基于给定的文字说明构建适合于DeepSeek API调用的形式""" prompt_template = "创造一张{style}的人物肖像, 场景设定为{surrondings}, 整体色调偏向{color_tone}" style_keywords = ["古风", "现代简约"] surronding_elements = ["森林边缘", "城市夜景"] color_palettes = ["暖橙色系", "冷蓝色调"] selected_style = next((kw for kw in style_keywords if kw in description), None) chosen_surrondings = next((elmt for elmt in surronding_elements if elmt in description), "") preferred_colors = next((clr for clr in color_palettes if clr in description), "") formatted_prompt = prompt_template.format( style=selected_style, surrondings=chosen_surrondings, color_tone=preferred_colors ) return formatted_prompt.strip() ``` #### 发送请求至服务器端口 准备好上述所有准备工作之后就可以向远程API发送HTTP POST请求来触发实际的任务执行流程了。注意要妥善处理可能遇到的各种异常情况以保证程序健壮性。 ```python try: response = client.create_image(prompt=get_prompt('古风少女、樱花背景')) except Exception as e: print(f"Error occurred during image creation: {str(e)}") else: with open('./output/generated_artwork.png', 'wb') as f: f.write(response.content) print("Image generation completed successfully!") ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值