题目描述

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"

输入输出样例

输入样例#1:

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
输出样例#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的更多相关文章

  1. 【LOJ#2162】【POI2011】Garbage(欧拉回路)

    [LOJ#2162][POI2011]Garbage(欧拉回路) 题面 LOJ 题解 首先有一个比较显然的结论,对于不需要修改颜色的边可以直接删掉,对于需要修改的边保留.说白点就是每条边要被访问的次数 ...

  2. [LOJ #2162]「POI2011」Garbage

    题目大意:给一张$n$个点$m$条边的无向图,每条边是黑色的或白色的,要求变成一个目标颜色.可以从任意一个点开始,走一个简单环,回到开始的点,所经过的边颜色翻转.可以走无数次.问是否有一个方案完成目标 ...

  3. [POI2011]Garbage 欧拉回路

    [POI2011]Garbage 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2278 https://loj.ac/problem/216 ...

  4. BZOJ2278 : [Poi2011]Garbage

    如果两个环相交,那么相交的部分相当于没走. 因此一定存在一种方案,使得里面的环都不相交. 把不需要改变状态的边都去掉,剩下的图若存在奇点则无解. 否则,每找到一个环就将环上的边都删掉,时间复杂度$O( ...

  5. BZOJ2278 [Poi2011]Garbage[欧拉回路求环]

    首先研究环上性质,发现如果状态不变的边就不需要动了,每次改的环上边肯定都是起末状态不同的边且仅改一次,因为如果有一条边在多个环上,相当于没有改,无视这条边之后,这几个环显然可以并成一个大环.所以,我们 ...

  6. POI2011题解

    POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...

  7. Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译

    本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  8. BZOJ2527: [Poi2011]Meteors

    补一发题解.. 整体二分这个东西,一开始感觉复杂度不是很靠谱的样子 问了po姐姐,说套主定理硬干.. #include<bits/stdc++.h> #define ll long lon ...

  9. (四)G1 garbage collector

    g1专为大内存,多内核机型设计.可以兼顾高吞吐量和低暂停时间. g1将堆分为多个相同大小内存块,并发的标记线程,使得g1掌握了各个内存块的活对象数量, 内存回收阶段,g1根据用户指定的暂停时间,选择部 ...

随机推荐

  1. DNS排查技术图谱

    # DNS排查技术图谱 ## 应用程序视角- 应用程序 - 浏览器 - hostname cache - ping- 操作系统 - hostname cache - 域名解析器 - dig domai ...

  2. vue组件通信之父组件主动获取子组件数据和方法

    ref 可以用来获取到dom节点,如果在组件中应用,也可以用来获取子组件的数据和方法. 比如,我定义了一个home组件,一个head组件,home组件中引用head组件. 此时,home组件是head ...

  3. zabbix--添加host

    在client配置好zabbix_agent后,如果server端没配置自动发现,那就需要创建添加host. 首先找到地方.Configuration--Hosts--Create Host 创建ho ...

  4. pytest-文件名类名方法名执行部分用例

    pytest test_class_01.py 执行文件名 pytest -v -s test_class_01.py 执行文件名 pytest -v test_class_01.py::TestCl ...

  5. javascript中的insertBefore方法

    <SCRIPT LANGUAGE="JavaScript"> window.onload=function(){ var a =document.createEleme ...

  6. 使用sublime+platUML快速画流程图

    程序员难免要经常画流程图,状态图,时序图等.以前经常用 visio 画,经常为矩形画多大,摆放在哪等问题费脑筋.有时候修改文字后,为了较好的显示效果不得不再去修改图形.今天介绍的工具是如何使用 Sub ...

  7. 转载:mysql sql_safe_updates 分析

    今天看到一个很实用的功能,mysql_safe_updates. 只是对功能做了转载,具体原理可以看一下 delete from table t where true ; update t set c ...

  8. lsm和lkm模块

    使用LSM Hook框架进行内核安全审计.元数据捕获,安全人员只需要按照既定的调用规范编写LKM模块,并加载进Linux内核,而不需要对system call lookup表进行任何修改 https: ...

  9. Mysql流程解析

    Mysql流程解析 流程图 流程图解析 客户端发送一条sql语句. 1.此时,mysql会检查sql语句,查看是否命中缓存,如果命中缓存,直接返回结果,不继续执行.没有命中则进入解析器. 2.解析器会 ...

  10. 49. ArrayList LinkedList中特有的方法

    集合的体系:--------------| Collection  单列集合的根接口 ----------| List 如果实现了List接口的集合类,该类具备的特点是:有序,可重复 ------|A ...