【题目链接】:http://codeforces.com/contest/796/problem/C

【题意】



给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被

打掉,但打掉一个点之后,与它距离小于等于2的节点的权值会增加1(如果中间节点有被打掉的,则不增加,即被切断了);

重复上述步骤,直至所有节点被打掉,能打掉某个节点,你需要满足:你的权值大于等于这个节点的权值.求一开始你的

权值的最小值;

【题解】



枚举每一个点作为第一个打掉的点,除了和它距离为1的那些点权值只递增1之外,其他点都会递增2,用multiset维护除了这个点和距离为1的点之外的点的权值的最大值

用这个点权值a[i],距离为1的那些点的权值(a2[i]+1),以及multiset的(头结点的权值+2)这3个值中的最大值来获取你打掉所有节点且从第i个节点开始打需要的权值的最小值;

对于第一次选取的点只选最大值是有漏洞的如

3

3 2 3

1 2

2 3

选2的话答案更优为4

选3则为5了



【Number Of WA】



4



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 3e5+100; int a[N],n,ans=21e8;
vector <int> G[N];
multiset<int,greater<int>> myset; void dele(int x)
{
__typeof(myset.begin()) t;
t = myset.find(x);
myset.erase(t);
} int main()
{
// freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
rei(a[i]),myset.insert(a[i]);
rep1(i,1,n-1)
{
int x,y;
rei(x),rei(y);
G[x].ps(y),G[y].ps(x);
}
rep1(i,1,n)
{
dele(a[i]);
int ma = a[i];
for (int y:G[i])
{
dele(a[y]);
ma = max(ma,a[y]+1);
}
if (!myset.empty())
ma = max(ma,*myset.begin()+2);
for (int y:G[i])
myset.insert(a[y]);
myset.insert(a[i]);
ans = min(ans,ma);
}
printf("%d\n",ans);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 796C】Bank Hacking的更多相关文章

  1. 【codeforces 796C】Bank Hacking(用一些技巧来代替multiset)

    [题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...

  2. 【codeforces 794A】Bank Robbery

    [题目链接]:http://codeforces.com/contest/794/problem/A [题意] 每个位置上可能有物品(>=1)或是没物品 你一开始在某一个位置b; 然后你最左可以 ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 750F】New Year and Finding Roots

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. new Modifier (C# Reference)

    https://msdn.microsoft.com/en-us/library/435f1dw2.aspx When used as a declaration modifier, the new  ...

  2. Dictionary<string, string>是一个泛型使用说明

    Dictionary<string, string>是一个泛型使用说明 Posted on 2010-08-05 15:03 moss_tan_jun 阅读(2273) 评论(0) 编辑  ...

  3. C#使用Quartz.NET详解

    Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...

  4. extern_c

    (1)    使用extern和包含头文件来引用函数有什么区别呢?extern的引用方式比包含头文件要简洁得多!extern的使用方法是直截了当的,想引用哪个函数就用extern声明哪个函数.这大概是 ...

  5. bzoj1833

    http://www.lydsy.com/JudgeOnline/problem.php?id=1833 2.5个小时就花在这上面了... 水到200题了...然并卵,天天做水题有什么前途... #i ...

  6. STM32:TIMER PWM 输入检测

    PWM输入检测是输入捕获的一个特例,可以测量频率与占空比 与输入捕获不同的是PWM输入模式会将同一个输入信号(TI1或TI2)连接到两个捕获装置(IC1和IC2).这两个捕获装置一个捕获上升沿一个捕获 ...

  7. 2-1 创建第一个Vue实例

    https://cn.vuejs.org/ 生产版本是经过压缩后的版本,它里面把一些没用的警告的代码删除掉了所以它会更精悍一些. 直接引入CDN的网址我们就可以使用Vuejs了.使用生产版本或者CDN ...

  8. PCB Genesis脚本 C#调用Javascript

    曾经用node.js测试写Genesis脚本失败了,这次借助开发PCB规则引擎的机会(基于JS V8引擎与.net深度交互性), 验证一下Javascript是否可用于写Genesis脚本. 一.测试 ...

  9. Rails5 Controller Document

    更新: 2017/06/28 大致完成全部 更新: 2017/06/29 补充module文件命名规则 更新: 2017/07/09 补充session的设置 更新: 2018/03/06 修正ren ...

  10. AirtestIDE详解(跨平台的UI自动化编辑器)

    Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. AirtestIDE 是一个跨平台.多端(Windows.web.android.ios.游戏)的UI自动化测 ...