[POI2011]SMI-Garbage
题目描述
http://main.edu.pl/en/archive/oi/18/smi
The Byteotian Waste Management Company (BWMC) has drastically raised the price of garbage collection lately. This caused some of the citizens to stop paying for collecting their garbage and start disposing of it in the streets. Consequently, many streets of Byteburg are literally buried under litter.
The street system of Byteburg consists of intersections, some of which are directly connected with bidirectional streets. No two streets connect the same pair of intersections. Some of the streets are littered while others are not.
The mayor of Byteburg, Byteasar, has decided on an unprecedented action to persuade the citizens to pay for waste collection. Namely, he decided to clean only some of the streets - precisely those that the majority of people living on paid for garbage collection. The streets that the majority of people living on did not pay for waste collection, on the other hand, will thus remain littered - or if it is called for - will become littered by the garbage collected from other streets! Byteasar has already prepared a city map with the streets to be cleaned and to remain or become littered marked on. Unfortunately, the BWMC employees cannot comprehend his master plan. They are, however, quite capable of carrying out simple instructions.
A single such instruction consists in driving the garbage truck along a route that starts on an arbitrary intersection, goes along any streets of choice, and ending on the very same intersection that it started on. However, every intersection can be visited at most once on a single route, except for the one it starts and ends with-the garbage truck obviously appears twice on that one. The truck cleans a littered street it rides along, but on the other hand it dumps the waste on the clean streets along its route, making them littered.
Byteasar wonders if it is possible to execute his plan by issuing a number of aforementioned route instructions. Help him out by writing a program that determines a set of such routes or concludes that it is impossible.
给定n个点m条边,每条边有一个初始权值0或1,有一个最终权值0或1,每次可以给一个简单环上的边权值异或1,求一种方案使得每条边从初始权值变成最终权值,无解输出"NIE"
输入输出样例
6 8
1 2 0 1
2 3 1 0
1 3 0 1
2 4 0 0
3 5 1 1
4 5 0 1
5 6 0 1
4 6 0 1
2
3 1 3 2 1
3 4 6 5 4 分析:
模板题em。。。欧拉回路中最简单的一道题。。。然而我不会???因为我第一个做这题的。。。
CODE:
来源于https://loj.ac/submission/512425
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector> const int maxn = 1e5 + ;
const int maxm = 2e6 + ; using namespace std; int cnt;
int d[maxn];
int to[maxm];
int nex[maxm];
int last[maxn], k = ;
int q[maxn], top;
int inq[maxn];
int vis[maxm];
vector<int> ans[maxn]; inline int read() {
int x = ;
char ch = getchar();
while (ch < '' || ch > '') ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar();
return x;
} int rit[], rits;
void write(int x) {
for (int i; x; x = i) i = x / , rit[++rits] = x - i * ;
while (rits) putchar(rit[rits--] + '');
} inline void add_edge(int x, int y) {
to[++k] = y;
nex[k] = last[x];
last[x] = k;
} void dfs(int x) {
if (inq[x]) {
++cnt;
int y = ;
do
y = q[top--], inq[y] = , ans[cnt].push_back(y);
while (y != x);
}
for (int &i = last[x]; i; i = nex[i])
if (!vis[i])
vis[i] = vis[i ^ ] = , inq[q[++top] = x] = , dfs(to[i]);
} int main(void) {
int n = read(), m = read();
while (m--) {
int x = read(), y = read(), a = read(), b = read();
if (a ^ b) {
add_edge(x, y);
add_edge(y, x);
d[x] ^= ;
d[y] ^= ;
}
}
for (register int i = ; i <= n; i++)
if (d[i]) {
cout << "NIE\n";
return ;
}
for (register int i = ; i <= n; i++) dfs(i);
write(cnt), putchar('\n');
for (register int i = ; i <= cnt; i++) {
write(ans[i].size()), putchar(' ');
for (int j = ; j < ans[i].size(); j++) write(ans[i][j]), putchar(' ');
write(ans[i][]), putchar('\n');
} return ;
}
[POI2011]SMI-Garbage的更多相关文章
- 【LOJ#2162】【POI2011】Garbage(欧拉回路)
[LOJ#2162][POI2011]Garbage(欧拉回路) 题面 LOJ 题解 首先有一个比较显然的结论,对于不需要修改颜色的边可以直接删掉,对于需要修改的边保留.说白点就是每条边要被访问的次数 ...
- [LOJ #2162]「POI2011」Garbage
题目大意:给一张$n$个点$m$条边的无向图,每条边是黑色的或白色的,要求变成一个目标颜色.可以从任意一个点开始,走一个简单环,回到开始的点,所经过的边颜色翻转.可以走无数次.问是否有一个方案完成目标 ...
- [POI2011]Garbage 欧拉回路
[POI2011]Garbage 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2278 https://loj.ac/problem/216 ...
- BZOJ2278 : [Poi2011]Garbage
如果两个环相交,那么相交的部分相当于没走. 因此一定存在一种方案,使得里面的环都不相交. 把不需要改变状态的边都去掉,剩下的图若存在奇点则无解. 否则,每找到一个环就将环上的边都删掉,时间复杂度$O( ...
- BZOJ2278 [Poi2011]Garbage[欧拉回路求环]
首先研究环上性质,发现如果状态不变的边就不需要动了,每次改的环上边肯定都是起末状态不同的边且仅改一次,因为如果有一条边在多个环上,相当于没有改,无视这条边之后,这几个环显然可以并成一个大环.所以,我们 ...
- POI2011题解
POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- BZOJ2527: [Poi2011]Meteors
补一发题解.. 整体二分这个东西,一开始感觉复杂度不是很靠谱的样子 问了po姐姐,说套主定理硬干.. #include<bits/stdc++.h> #define ll long lon ...
- (四)G1 garbage collector
g1专为大内存,多内核机型设计.可以兼顾高吞吐量和低暂停时间. g1将堆分为多个相同大小内存块,并发的标记线程,使得g1掌握了各个内存块的活对象数量, 内存回收阶段,g1根据用户指定的暂停时间,选择部 ...
随机推荐
- RF中alert的处理
那么在robotframework中如何处理呢? 我在测试过程中遇到了这么一个窗口: 这种应该是属于Confirm 类型,是无法定位到的,在robotframework中需要这样处理: 1.虽然无法定 ...
- 杂项-Conda:Conda
ylbtech-杂项-Conda:Conda 1.返回顶部 1. Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换. 外文名:Con ...
- 比较器CompareTo的使用
比较器CompareTo的使用 源码 package test; import java.text.SimpleDateFormat; import java.util.Date; public cl ...
- SSM项目启动报错:Failed to read candidate component class
SSM项目启动报错:Failed to read candidate component class 换成3.1又没有问题,换成3.2又不行,查看编译环境用的是1.8,将1.8降为1.7,问题解决,服 ...
- TLS/SSL 协议 - Server Certificate
Server Certificate 典型的Certificate消息用于携带服务器X.509证书链.证书链是以ASN.1 DER编码的一系列证书,一个接着一个组合而成.主证书必须第一个发送,中间证书 ...
- java有序列表
关于有序和无序的定义: 有序:有序列表中的元素具有某种内在的关联,这种关联定义了列表之间的顺序 无序:无序列表中的元素按使用者所选择得任意方式排序 索引:索引列表为他的元素维护一段连续的数字索引值 有 ...
- 牛客 最大值减去最小值小于或等于 num 的子数组数量
题目链接:https://www.nowcoder.com/practice/5fe02eb175974e18b9a546812a17428e?tpId=101&tqId=33086& ...
- C#基础-->cookie和session
关于cookie和session cookie 1:一个cookie中可以存放的数据最大在4KB左右 2:cookie存放于客户端 3:cookie分为两种 一种是会话cookie 一种是持久co ...
- CSS3:FlexBox的详解
Flexbox是Flexible box 的简称(灵活的盒子容器),是CSS3引入的新的布局模式.它决定了元素如何在页面上排列,使它们能在不同的屏幕尺寸和设备下可预测地展现出来. 它之所以被称为 Fl ...
- zabbix--添加用户
用户和用户组 概述 Zabbix 中的所有用户都通过 Web 前端去访问 Zabbix 应用程序.并为每个用户分配唯一的登陆名和密码. 所有用户的密码都被加密并储存于 Zabbix 数据库中.用户 ...