Codeforces 269C Flawed Flow (看题解)
我好菜啊啊啊。。
循环以下操作
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 (看题解)的更多相关文章
- CodeForces - 269C Flawed Flow
http://codeforces.com/problemset/problem/269/C 题目大意: 给定一个边没有定向的无法增广的残量网络且1是源点,n是汇点,给定每条边中的流. 让你把所有边 ...
- codeforces 269C Flawed Flow(网络流)
Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious prog ...
- Codeforces 436E Cardboard Box (看题解)
Cardboard Box 贪了个半天贪不对, 我发现我根本就不会贪心. 我们先按b排序, 然后枚举选两颗心的b的最大值, 在这个之前的肯定都要选一个, 因为前面的要是一个都没选的话, 你可以把当前选 ...
- Codeforces 1045C Hyperspace Highways (看题解) 圆方树
学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...
- Codeforces 1137D Cooperative Game (看题解)
Cooperative Game 智商题, 感觉不太能推出来, 虽然看看证明过程是对的. #include<bits/stdc++.h> #define LL long long #def ...
- Codeforces 875F Royal Questions (看题解)
我还以为是什么板子题呢... 我们把儿子当做点, 公主当做边, 然后就是求边权值最大基环树森林. #include<bits/stdc++.h> #define LL long long ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Codeforces 924D Contact ATC (看题解)
Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...
- Codeforces 830C Bamboo Partition (看题解)
Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi ...
随机推荐
- Hibernate_day03
一.今天内容 0 列表功能实现 1 表与表之间关系回顾 (1)一对多(客户和联系人) (2)多对多(用户和角色) 2 hibernate一对多操作 (1)一对多映射配置 (2)一对多级联保存 (3)一 ...
- jquery 兼容的滚轮事件
// jquery 兼容的滚轮事件 $(document).on("mousewheel DOMMouseScroll", function (e) { ? : -)) || // ...
- Windows句柄数限制
设置 GDIProcessHandleQuota项设置GDI句柄数量,默认值为2710(16进制)/10000(10进制),该值的允许范围为 256 ~ 16384 ,将其调整为大于默认的10000的 ...
- vue自学入门-2(vue创建项目)
本人也是刚学习VUE,边找资料,边学习,边给大家分享.1.创建项目 2.启动项目 3.注意上面和下面全部用cnpm
- 表格重新加载 where 携带上次值问题
表格重载两种方式: 方式一: tableIns.reload(options) 注意这种方式的重载是不会携带上次数据加载时的where值 //使用 第一次渲染返回的对象 var table ...
- qemu基本使用
1.qemu的安装 请参考家用路由器0day漏洞挖掘技术这本书 2.基本使用 qemu有主要如下两种运作模式: 用户模式(User Mode),亦称使用者模式.qemu能启动那些为不同中央处理器编译的 ...
- javascript 回到顶部
<script type="text/javascript"> window.onload = function(){ var timer = null; //用于判断 ...
- Python中的部分特殊属性
__name__ is the class name; 返回类名 __module__ is the module name in which the class was defined; 定 ...
- python - class类 (六) 三大特性 - 多态
多态的概念: # 多态的概念 # 指出了对象如何通过他们共同的属性和动作来操作及访问而不需考虑他们的具体的类 # 多态表明了动态绑定的存在,允许重载及运行时类型确定和验证. # 示例模拟: #水具有多 ...
- Centos7.5 防火墙设置
Centos7.5默认使用firewalld作为防火墙 1.查看firewalld服务状态 systemctl status firewalld 2.查看firewalld的状态 firewall-c ...