http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1307

题意:

思路:

可以直接二分答案,然后dfs。

因为标签是并查集,所以我考虑了一下并查集,利用并查集不断向上回溯加负重,居然过了,只能说数据有点水。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn=+;
const int mod=1e9+; int n;
int p[maxn];
int c[maxn],w[maxn],f[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
for(int i=;i<n;i++) p[i]=i;
int ans=n;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&c[i],&w[i],&f[i]);
if(ans!=n) continue;
if(f[i]==-) continue;
p[i]=f[i];
int x=i;
while(true)
{
x=p[x];
w[x]+=w[i];
if(w[x]>c[x]) {ans=i;break;}
if(x==p[x]) break;
}
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. [翻译] AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)
  2. 利用ssh-copy-id无需密码登录远程服务器
  3. ubuntu 下安装 lxml 失败
  4. context:component-scan 分析
  5. visual2012 快捷键
  6. [置顶] Android Journal
  7. python自动化运维:系统基础信息模块
  8. Spring Cloud配置中心搭建(集成Git)
  9. Scrapy 扩展中间件: 针对特定响应状态码,使用代理重新请求
  10. WebAssembly让你的Javascript计算性能提升70%
  11. webstorm keys
  12. 学习笔记 requests + BeautifulSoup
  13. Faiss教程:索引(2)
  14. openssl AES加密
  15. mybatis---属性和字段映射
  16. [svc][op]磁盘(结构)容量计算
  17. react +MUI checkbox使用
  18. jquery 无刷新添加/删除 input行 实时计算购物车价格
  19. (step6.1.1)hdu 1879(继续畅通工程——最小生成树、kruscal)
  20. Linux下32位与64位数据类型大小

热门文章

  1. host文件常用地址
  2. golang 的精髓--pipeline流水线,对现实世界的完美模拟
  3. [运维-安全]CentOS7.0环境下安装kangle和easypanel
  4. libSVM简介及核函数模型选择
  5. PNG格式图片常见转换方法
  6. liferay中如何获取实例的id和portletId
  7. ts实战项目启动中遇到的问题
  8. http-equiv=&quot;Refresh&quot; 实现定时刷新页面
  9. tensorflow显存管理
  10. ADO.NET知识学习总结