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

 #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. php文件上传 form表单形式

    1.php界面 <?php header( 'Content-Type:text/html;charset=utf-8 ');include_once("conn/conn.php&q ...

  2. ubantu安装apache

    1.命令安装: sudo apt install apache2 2.检查是否启动了Apache服务 systemctl status apache2 3.开启.关闭和重启服务器 /etc/init. ...

  3. day02_1spring3

    面向切面编程.AOP手动代理和spring编写代理 一.什么是AOP 1.AOP简介: 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方 ...

  4. 解决ASP.Net第一次访问慢的处理 IIS 7.5

    1.先安装ApplicationInitialization Module for IIS 7.5(微软发布的针对针对前期的IIS单独模块),再安装ApplicationInitialization ...

  5. [codeigniter4]Upgrading from 3.x to 4.x

    CodeIgniter 4 is a rewrite of the framework, and is not backwards compatible. It is more appropriate ...

  6. PVE上安装黑裙辉6.2

    参考文章:https://post.smzdm.com/p/a25r8mo2/ http://www.myxzy.com/post-488.html 环境介绍 1.Proxmox VE(以下简称PVE ...

  7. IntelliJ IDEA 2017.3-----导入jar包

    1.选择jar包 2.右键选择 3.点击ok

  8. java中成员变量,局部变量,静态变量的辨析

    转自百度:https://baijiahao.baidu.com/s?id=1625360816541592483&wfr=spider&for=pc 1.java中成员变量,局部变量 ...

  9. C# MVC扩展方法

    控制方法 : 在不修改类原来代码的情况下,给类扩展方法 https://www.cnblogs.com/jxsimon/articles/5043654.html https://www.cnblog ...

  10. Codeforces Round #598 (Div. 3) B Minimize the Permutation

    B. Minimize the Permutation You are given a permutation of length nn. Recall that the permutation is ...