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

 #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. CI系列之配置sonar

    基于GO项目 1.在jenkins新建sonar任务,设置2个变量用于接收代码分支和pipline的workspace[两个变量的作用在CI之Jenkinsfile中会讲到] A.添加构建参数 B.选 ...

  2. markdown文本编辑学习笔记2

    目录 1.删除线 2.无序列表 4 todo list 5分割符号 6 TOC自动生成目录 7 插入代码块 8 斜体.粗体.删除线.下划线.背景高亮 markdown编辑公式 1.删除线 ~~要删除的 ...

  3. ❀❀ selenium 学习网站 ★★★★★

    http://edu.51cto.com/course/course_id-7320.html   Selenium IDE WEB自动化测试入门视频课程(上)(共10课时)_在线自学视频教程_51C ...

  4. EntityFramework之原始查询及性能优化

    之前做海信项目,数据量自交大,为了提高查询效率用的 https://www.cnblogs.com/CreateMyself/p/4746258.html

  5. vue小例子-01

    1.在components下建一个 2.代码如下: <template> <!--1.业务是开始有一组数据,序号,姓名,性别,年龄,操作(删除)     2.有三个输入框输入姓名,性 ...

  6. [CF484D] Kindergarten - 贪心

    有一组数,你要把他分成若干连续段.每一段的值,定义为这一段 数中最大值与最小值的差. 求一种分法,使得这若干段的值的和最大. N < 1e6, a[i] < 1e9. 朴素的\(O(n^2 ...

  7. Linux 配置mysql 远程连接

    1.首先用root用户登录mysql mysql -u root -p 2.新建用户 use mysql; select host,user from user;(查看现有用户) CREATE USE ...

  8. 关于Win32串口

    因为近段时间接触Hid相对来说多一些,由此忽略了串口中获取cbInQue这个重要的东西,下面是错误代码 // Win32SerialPortLib.cpp : 定义 DLL 应用程序的导出函数. // ...

  9. egg.js 配置cors跨域

    1.egg简述 Egg.js,为企业级框架和应用而生,是阿里开源的企业级 Node.js 框架. 2.特点 Egg 奉行『约定优于配置』,按照一套统一的约定进行应用开发,团队内部采用这种方式可以减少开 ...

  10. SQL Server中使用msdb数据库的存储过程sp_delete_backuphistory和sp_delete_database_backuphistory来删除备份和恢复历史数据

    根据微软文档对sp_delete_backuphistory存储过程的介绍,SQL Server在每次备份和恢复数据库后,会向msdb系统数据库的备份和恢复历史表写入数据,如果SQL Server经常 ...