题目描述

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. spring AOP (使用AspectJ的xml方式 的aop实现) (7)

    目录 一.定义计算器接口跟实现类 二.定义两个切面,日志切面和验证切面 三.在xml中配置切面 四.测试类 一.定义计算器接口跟实现类 public interface ArithmeticCalcu ...

  2. Tomcat运行错误示例二

    Tomcat运行错误示例二 当遇到这种错误时,一般是构建路径的问题,按步骤来就好.如图: 点击---->库---->Add Library---->下一步---->选择tomc ...

  3. Git 学习第三天(一)

    远程克隆: 在github新建一个仓库,起名为gitskills 勾选此项,会自动创建一个readme.md文件,然后通过命令 git clone git@github.com:Your.name/g ...

  4. 常用的一些js事件及案例

    比如金额需要显示的时候转换成有千分位,小数点后保留2位等.去编辑的时候,又要格式化,把逗号都去掉.网上找了段代码,但是再次编辑会有问题,修改了一下,代码如下: function outputMoney ...

  5. swiper实现上下滑动翻页,内置内容页也滚动

    如果我猜的没错,是全网(哈哈)比较少的成功解决方案,如需要转载,请声明并转载出处. swiper实现了上下滑动翻页,但是有几个页面的内容显示不完.如果一页显示不完时可以滑动查看,应该怎么做?这个是我多 ...

  6. 【POJ】1679 The Unique MST

    题目链接:http://poj.org/problem?id=1679 题意:给你一组数据,让你判断是否是唯一的最小生成树. 题解:这里用的是kuangbin大佬的次小生成树的模板.直接判断一下次小生 ...

  7. pytest----fixture(1)--使用fixture执行配置及销毁逻辑

    1使用fixture执行配 置及销毁;非常灵活 使用. 2数据共享:在 conftest.py配置里写方 法可以实现数据共享, 不需要import导入.可 以跨文件共享 3scope的层次及神 奇的y ...

  8. Linux下的Ngnix服务器部署静态页

    一.安装FTP vsftpd 的名字代表”very secure FTP daemon”, 安全是它的开发者 Chris Evans 考虑的首要问题之一.在这个 FTP 服务器设计开发的最开始的时候, ...

  9. 安装Storm的基本过程

  10. Java调用Linux下的shell命令并将结果以流的形式返回

    import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader; public cl ...