我好菜啊啊啊。。

循环以下操作

1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向。

2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列。

现在有一个问题就是, 有没有可能队列中为空还没有更新完毕, 这是不可能的,

我们能这么考虑, 其中一个点x的入度还没有满, 那么我们能推出(u, x)还没有被确认, 说明u还没入队,

因为原图为有向图, 所以最后一定会推到1, 这回产生矛盾, 所以这种情况不可能发生。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, ans[N], all[N], sum[N];
vector<pair<PII,int>> G[N]; int main() {
memset(ans, -, sizeof(ans));
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
G[a].push_back(mk(mk(b, c), i));
G[b].push_back(mk(mk(a, c), -i));
all[a] += c;
all[b] += c;
}
queue<int> que;
que.push();
while(!que.empty()) {
int u = que.front(); que.pop();
for(auto& e : G[u]) {
if(~ans[abs(e.se)]) continue;
if(e.se < ) {
ans[-e.se] = ;
sum[e.fi.fi] += e.fi.se;
} else {
ans[e.se] = ;
sum[e.fi.fi] += e.fi.se;
}
if(sum[e.fi.fi] * == all[e.fi.fi])
if(e.fi.fi != n) que.push(e.fi.fi);
}
}
for(int i = ; i <= m; i++) printf("%d\n", ans[i]);
return ;
} /*
*/

Codeforces 269C Flawed Flow (看题解)的更多相关文章

  1. CodeForces - 269C Flawed Flow

    http://codeforces.com/problemset/problem/269/C 题目大意: 给定一个边没有定向的无法增广的残量网络且1是源点,n是汇点,给定每条边中的流.  让你把所有边 ...

  2. codeforces 269C Flawed Flow(网络流)

    Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious prog ...

  3. Codeforces 436E Cardboard Box (看题解)

    Cardboard Box 贪了个半天贪不对, 我发现我根本就不会贪心. 我们先按b排序, 然后枚举选两颗心的b的最大值, 在这个之前的肯定都要选一个, 因为前面的要是一个都没选的话, 你可以把当前选 ...

  4. Codeforces 1045C Hyperspace Highways (看题解) 圆方树

    学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...

  5. Codeforces 1137D Cooperative Game (看题解)

    Cooperative Game 智商题, 感觉不太能推出来, 虽然看看证明过程是对的. #include<bits/stdc++.h> #define LL long long #def ...

  6. Codeforces 875F Royal Questions (看题解)

    我还以为是什么板子题呢... 我们把儿子当做点, 公主当做边, 然后就是求边权值最大基环树森林. #include<bits/stdc++.h> #define LL long long ...

  7. Codeforces 983C Elevator dp (看题解)

    Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...

  8. Codeforces 924D Contact ATC (看题解)

    Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...

  9. Codeforces 830C Bamboo Partition (看题解)

    Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi ...

随机推荐

  1. .NET面试题系列(十五)yong

    Redis为什么使用单进程单线程方式也这么快 Redis遍历所有key的两个命令 -- KEYS 和 SCAN 一致性Hash算法 利用一致性哈希水平拆分MySql单表 单例模式  锁 双重锁 单例模 ...

  2. Tukey‘s test方法 异常值

    如何计算异常值 异常值就是和其他样本数据有显著差异的值.这个词在统计学中经常用到,可以表示数据异常或测量错误.明白算异常值的方法,对于正确理解数据非常有用,而且会引出更精确的结论.以下介绍一个很简单的 ...

  3. OracleHelper与SqlServerHelper

    1.OracleHelper using System; using System.Data; using System.Configuration; using System.Linq; using ...

  4. C# 简单的反射机制实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  5. 【摘】SVN提交与版本冲突

    一般性解决办法 1.要提交的内容备份到项目之外[为还原版本做准备] 2.还原[回到之前版本] 3.更新[更新版本号和版本] 4.填充内容[即 将自己之前备份的内容填充项目对应处] 5.提交 6.OK ...

  6. java中String类型

    string对象常用方法 string对象比较方法: string类获取包含子串的方法: 字符串和数字的转换: String类 String对象是不可改变的,字符串一旦创建,内容不能再改变. 构造字符 ...

  7. 使用matplotlib绘制多个图形单独显示

    使用matplotlib绘制多个图形单独显示 一 代码 import numpy as np import matplotlib.pyplot as plt #创建自变量数组 x= np.linspa ...

  8. kafka系列八、kafka消息重复和丢失的场景及解决方案分析

    消息重复和丢失是kafka中很常见的问题,主要发生在以下三个阶段: 生产者阶段 broke阶段 消费者阶段 一.生产者阶段重复场景 1.根本原因 生产发送的消息没有收到正确的broke响应,导致pro ...

  9. zookeeper3.4.6配置实现自动清理日志

    在使用zookeeper过程中,我们知道,会有dataDir和dataLogDir两个目录,分别用于snapshot和事务日志的输出(默认情况下只有dataDir目录,snapshot和事务日志都保存 ...

  10. 创建物理卷报错Can't open /dev/sdb5 exclusively. Mounted filesystem的问题解决过程记录

    yum服务器lvm扩容,data目录是yum存放rpm包的目录,只有20G,需要添加磁盘扩容到80G # df -lh Filesystem                 Size  Used Av ...