[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根据用户指定的暂停时间,选择部 ...
随机推荐
- Useful code snippets with C++ boost
Useful code snippets with C++ boost Is Punctuation It’s very straight forward to use boost.regex as ...
- python中处理.mat文件
python中处理.mat文件 背景 在实际使用python的时候,发现很多数据都是使用.mat的形式保存,所以,如何使用python读写.mat文件成为了许多python使用者必备的技能. -v7. ...
- Navicat 连接MongoDB 查询语句
https://www.cnblogs.com/viviman/archive/2012/11/21/2780562.html
- myeclipse 启动卡住的解决办法
myeclipse 启动卡住的解决办法 今天启动myeclipse突然卡住,CPU一直占用,启动任务管理器强制关闭.重启myeclipse,重启电脑都不能够解决. 上网查找,在工程路径(工作空间的路径 ...
- linux进阶之路(三):vi/vim编辑器
所有Linux都会内置vi,vim是vi的增强版本,被誉为"编辑之神",玩转vim可以让你完全脱离鼠标. vim可以分为两种模式: 普通模式:使用vim 文件名,进入普通模式.普通 ...
- hbase之setCaching 和 setBatch 和setMaxResultSize
scan的setBatch()用法 val conf = HBaseConfiguration.create() val table: Table = ConnectionFactory.create ...
- CentOS 7 启用中文输入法
$HOME/.xinitrc LANG="zh_CN.UTF-8" exec startxfce4
- [已解决]报错This event loop is already running
安装nest_asyncio pip install nest_asyncio 导入并调用 import nest_asyncio nest_asyncio.apply()
- 2018年初面试Java(1.5年经验)
xml文档如何解析 控制反转如何实现 http://www.cnblogs.com/qf123/p/8602972.html struts2和springmvc的区别 http://www.cnblo ...
- cocos2dx 3.9 微信授权登陆后游戏进程结束解决办法
找到 Cocos2dxActivity.java 文件夹 里面的 onDestroy() 方法 if (mGLSurfaceView != null) { Cocos2dxHel ...