博客
关于我
Codeforces Round #592 (Div. 2) D. Paint the Tree(构造)
阅读量:387 次
发布时间:2019-03-05

本文共 3378 字,大约阅读时间需要 11 分钟。

??????????????????????????????????????????????a[i], b[i], c[i]????????????????

????

?????????????????????????????????????????????????

  • ???????????????????????????????????????????????????
  • ?????????????????????????????????????????????????
  • ???????????????????????????????????????????????????6?????????????????
  • ????????????????????????????????????????
  • ????

    #include 
    #include
    using namespace std;const int maxn = 1e5 + 5;vector
    g[maxn];ll a[maxn], b[maxn], c[maxn];ll ans[7][maxn];ll minn = 2e18;ll temp;void dfs(int x, int fa, int prev_color, int current_color, int deep, int id) { if (deep % 3 == 1) { ans[id][x] = a[x]; } else if (deep % 3 == 2) { ans[id][x] = b[x]; } else { ans[id][x] = c[x]; } for (int to : g[x]) { if (to == fa) continue; dfs(to, x, current_color, prev_color, deep + 1, id); }}int main() { int n, k, x, y; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } for (int i = 1; i <= n; ++i) { scanf("%d %d", &x, &y); g[x].push_back(y); g[y].push_back(x); } if (g[1].size() != n - 1) { puts("-1"); return 0; } vector
    > order(n); for (int i = 1; i <= n; ++i) { order[i - 1] = make_pair(g[i][0], g[i][1]); } int root = 1; for (int i = 1; i <= n; ++i) { if (g[i].size() != 1) { puts("-1"); return 0; } } for (int init1 = 1; init1 <= 3; ++init1) { for (int init2 = 1; init2 <= 3; ++init2) { if (init1 == init2) continue; for (int init3 = 1; init3 <= 3; ++init3) { if (init1 != init3 && init2 != init3) { int id = 1; for (int i = 1; i <= n; ++i) { if (order[i - 1].first == i) { continue; } if (order[i - 1].second != i) { puts("-1"); return 0; } } dfs(root, -1, -1, init1, 1, 1); dfs(root, -1, init1, init2, 1, 2); dfs(root, -1, init1, init3, 1, 3); dfs(root, -1, init2, init1, 1, 4); dfs(root, -1, init2, init3, 1, 5); dfs(root, -1, init3, init1, 1, 6); for (int i = 1; i <= 6; ++i) { temp = 0; for (int j = 1; j <= n; ++j) { if (ans[i][j] == 1) { temp += a[j]; } else if (ans[i][j] == 2) { temp += b[j]; } else { temp += c[j]; } } if (temp < minn) { minn = temp; } } } } } } cout << minn << endl; return 0;}

    ????

  • ?????????????????????????
  • ????????????????????????????????
  • ?????dfs????????????????????????????????
  • ???????????????????????????????????????
  • ???????????????????????????
  • ????????????????????????????????????????

    转载地址:http://trewz.baihongyu.com/

    你可能感兴趣的文章
    powershell对txt文件的服务器进行ping操作
    查看>>
    powershell常用
    查看>>
    PowerShell操作XML遇到的问题
    查看>>
    PowerShell攻击工具Empire实战
    查看>>
    PowerShell攻击工具Nishang实战
    查看>>
    PowerShell攻击工具PowerSploit实战
    查看>>
    Powershell管理系列(四)Lync server 2013 批量启用语音及分配分机号
    查看>>
    PowerShell脚本运行完 不要马上关闭用什么命令可以停留窗口窗口
    查看>>
    PowerShell远程连接到Windows
    查看>>
    power(8) identity
    查看>>
    POW的重力之美
    查看>>
    PO、VO、DAO、BO、DTO、POJO能分清吗?
    查看>>
    pytorch介绍-ChatGPT4o作答
    查看>>
    PP-PLL:基于概率传播的部分标签学习
    查看>>
    pytorch介绍
    查看>>
    pprint 排序字典但不是集合?
    查看>>
    pptp拨号上网
    查看>>
    ppt上的倒计时小工具_PPT中有哪些「看似很 LOW,实则惊艳」的小工具
    查看>>
    PPT添加视频的路径问题
    查看>>
    PPT美化插件 islide 安装过程问题“加载com加载项时运行出现错误”
    查看>>