[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根据用户指定的暂停时间,选择部 ...
随机推荐
- (转)Vmware vSphere 5.0系列教程 vSphere网络原理及vSwitch简介 及一个host两个网卡说明
转:http://andygao.blog.51cto.com/323260/817518/ 在一个物理网络拓扑中,通常都是路由器-交换机-PC机的连接,不同的服务器和PC机,通过交换机的连接而相互连 ...
- HDU 6651 Final Exam (思维)
2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...
- 剑指offer——54数组中的逆序对
题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%1000 ...
- 剑指offer——49礼物的最大价值
题目描述 在一个m*n的棋盘的每一格都放有一个礼物,每个礼物都有一定的价值(价值大于0).你可以从棋盘的左上角开始拿格子里的礼物,并每次向左或者向下移动一格,知道到达棋盘的右下角.给定一个棋盘及其上面 ...
- 20140604 word表格中打钩 循环右移
1.如在在word表格中打钩 符号->其他符号->字体(wingdings2) 2.循环右移 方法1: #include<stdio.h> void move(char *s) ...
- Java 序列化和反序列化(三)Serializable 源码分析 - 2
目录 Java 序列化和反序列化(三)Serializable 源码分析 - 2 1. ObjectStreamField 1.1 数据结构 1.2 构造函数 2. ObjectStreamClass ...
- Linux系统查看局域网的公网ip
访问http://www.cip.cc即可获得ip 前提是linux系统能够解析域名 [root@Test ~]# curl cip.cc IP : 115.216.41.112 地址 : 中国 浙江 ...
- tomcat启动内存修改
# USE_NOHUP (Optional) If set to the string true the start command will # ...
- ThreadLocal知识点
ThreadLocal是什么 ThreadLocal 表面上看他是和多线程,线程同步有关的一个工具类,但其实他与线程同步机制无关.线程同步机制是多个线程共享同一个变量,而ThreadLocal是为每个 ...
- map 结构体
map<node,int> 需要运算符重载< 请注意,不同的node,请务必让它们可以区分出来(node a,b a<b or b<a) 如 node { int a,i ...