一个人只要存在债务关系,那么他的债务可以和这整个债务关系网中任何人连边,和他当初借出或欠下的人没有关系。只需要记录他的债务值即可。

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long val[];
vector<array<long long,> >v;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin>>n;
long long m;
cin>>m;
for(long long i=;i<=m;++i){
long long a,b,c;
cin>>a>>b>>c;
val[a]-=c;
val[b]+=c;
}
long long pos=;
for(long long i=;i<=n;++i){
while(val[i]>){
while(val[pos]>=)
++pos;
long long mn=min(-val[pos],val[i]);
val[i]-=mn;
val[pos]+=mn;
v.push_back({pos,i,mn});
}
}
cout<<v.size()<<"\n";
for(auto it:v)
cout<<it[]<<" "<<it[]<<" "<<it[]<<"\n";
return ;
}

Codeforces Global Round 6D(VECTOR<ARRAY<INT,3> >)的更多相关文章

  1. Codeforces Global Round 1D(DP,思维)

    #include<bits/stdc++.h>using namespace std;int dp[1000007][7][7];int cnt[1000007];int main(){  ...

  2. Codeforces Global Round 5E(构造,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int main(){ ios::sync_w ...

  3. Codeforces Global Round 4E(字符串,思维)

    #include<bits/stdc++.h>using namespace std;string s,a,b;int main(){ cin>>s; int n=s.size ...

  4. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  5. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  6. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  7. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  8. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  9. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

随机推荐

  1. H3C IP路由基础

    一.路由简介 在网络中路由器根据所收到的报文的目的地址选择一条合适的路径,并将报文转发到下一个路由器.路径中最后一个路由器负责将报文转发给目的主机. 路由就是报文在转发过程中的路径信息,用来指导报文转 ...

  2. 并查集-E - Wireless Network

    E - Wireless Network An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  3. Codeforces Round #601 (Div. 2) A Changing Volume

    好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...

  4. 15分钟带你了解前端工程师必知的javascript设计模式(附详细思维导图和源码)

    15分钟带你了解前端工程师必知的javascript设计模式(附详细思维导图和源码) 前言 设计模式是一个程序员进阶高级的必备技巧,也是评判一个工程师工作经验和能力的试金石.设计模式是程序员多年工作经 ...

  5. 生成器和迭代器_python

    一.生成器简介(generator) 在进行较大数据的存储,如果直接存储在列表之中,则会可能造成内存的不够与速度的减慢,因为列表创建完是立即创建并存在的,而在python中生成器(generator) ...

  6. wamp 增加mongodb拓展 安装

    安装环境: windows 7 64bit php 5.5.12 确认环境参数: 1.在phpinfo() 中查看compiler 2.在phpinfo() 中查看thread safety,线程是否 ...

  7. [P3806] 【模板】点分治 - 点分治

    辣鸡蒟蒻怎么今天才来敲这个模板题 好像还敲了很久的样子 (大雾) #include <bits/stdc++.h> using namespace std; #define int lon ...

  8. Python JASON

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写. http://www.runoob.com/python/python-json.ht ...

  9. centost redhat 卸载rpm以及yum install 的正确姿势

    先看yum  install 的卸载: 第一列为我们要的包名: 那么要移除必须使用 yum list |grep  collectd | awk '{print $1}' |xargs  yum  r ...

  10. HTTP状态码的浪漫故事

    小明是一个程序员,经常加班,在一个和尚部门,一个妹子都没有,所以一直单身. 404(Not Found):服务器无法根据客户端的请求找到资源(网页) 过年回家,老爸老妈给门开一条缝,先看看小明身后-- ...