图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
/*
题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....)
图论/位运算:其实这题很简单。类似拓扑排序,先把度数为1的先入对,每一次少一个度数
关键在于更新异或和,精髓:a ^ b = c -> a ^ c = b, b ^ c = a;
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std; const int MAXN = 7e4 + ;
const int INF = 0x3f3f3f3f;
int ans[MAXN][];
int d[MAXN], s[MAXN]; int main(void) //Codeforces Round #285 (Div. 2) C. Misha and Forest
{
// freopen ("C.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
queue<int> Q;
for (int i=; i<n; ++i)
{
scanf ("%d%d", &d[i], &s[i]);
if (d[i] == ) Q.push (i);
} int cnt = ;
while (!Q.empty ())
{
int u = Q.front (); Q.pop ();
if (d[u] == ) continue;
int v = s[u];
ans[++cnt][] = u; ans[cnt][] = v;
if ((--d[v]) == ) Q.push (v);
s[v] = s[v] ^ u;
} printf ("%d\n", cnt);
for (int i=; i<=cnt; ++i)
{
printf ("%d %d\n", ans[i][], ans[i][]);
}
} return ;
}
图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest的更多相关文章
- 水题 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- Codeforces Round #285 (Div. 1) A. Misha and Forest 拓扑排序
题目链接: 题目 A. Misha and Forest time limit per test 1 second memory limit per test 256 megabytes 问题描述 L ...
- Codeforces Round #285 (Div. 2)C. Misha and Forest(拓扑排序)
传送门 Description Let's define a forest as a non-directed acyclic graph (also without loops and parall ...
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...
- Codeforces Round #285 (Div. 1) B - Misha and Permutations Summation 康拓展开+平衡树
思路:很裸的康拓展开.. 我的平衡树居然跑的比树状数组+二分还慢.. #include<bits/stdc++.h> #define LL long long #define fi fir ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- CodeForces Round #285 Div.2
C.Misha and Forest (图论 BFS) 比赛进行了一半才想起来有场CF没打,=_=|| 前两道题快速切掉,C题一直卡没什么好的思路 憋了几天,忍不住偷偷瞄了一下别人AC的代码,发现我题 ...
- Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...
随机推荐
- sgu208:Toral Tickets(Pólya定理)
题意简述:给你N和M,对于一个N∗M的单面方格纸你能够对它的每 个个格子黑白染色.然后把方格纸的长边卷起来,卷成一个圆柱体,然后再把 两个短边形成的圆也接起来.形成一个游泳圈的形状(我们染的色仅仅在游 ...
- nginx access.log 忽略favicon.ico訪问记录的方法
favicon.ico 文件是浏览器收藏网址时显示的图标,当第一次訪问页面时.浏览器会自己主动发起请求获取页面的favicon.ico文件.当/favicon.ico文件不存在时,服务器会记录404日 ...
- C++第9周(春)项目5 - 一元一次方程类
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目5]设计一元一次方程类.求形如ax+b= ...
- 国内博客(blog)搬家工具(服务)大全
如今网络上的博客搬家 服务,博客搬家工具 越来越多,博客联盟 大概收集了下,希望对那些想搬家的博客有所帮助. 一.和讯博客的“搬家公司”提供博客搬家 服务 搬家服务地址:点这里 目标对象:新浪博客 . ...
- ubuntu怎么打开.7z和.rar的压缩文件
通过 sudo apt-get install p7zip-rar就会自己主动安装p7zip-full和p7zip-rar两个软件. 之后就能够通过鼠标右键选择 提取到此处 直接解压压缩文件. den ...
- 怎样在 AutoLayout 中使用 UIScrollView (多个ContentView)
http://codehappily.wordpress.com/2013/11/14/ios-how-to-use-uiscrollview-with-autolayout-pure-autolay ...
- spinlock in linux kernel
spinlock in linux kernel 作为一种锁机制, spinlock可以制造一段临界区, 同一时刻只有一个线程能进入这个临界区, 从而达到保护数据的目的. semaphore, mut ...
- OpenGL中视点模型坐标的理解
个人的理解: gluLookAt中的eye.center和up的坐标原点是ModelView中的坐标原点,右手坐标系,Z轴正向指向显示器外侧 glOrtho中的near和far参数距离相对eye而言, ...
- Effective JavaScript Item 39 绝不要重用父类型中的属性名
本系列作为Effective JavaScript的读书笔记. 假设须要向Item 38中的Actor对象加入一个ID信息: function Actor(scene, x, y) { this.sc ...
- Node.js 101(2): Promise and async
--原文地址:http://blog.chrisyip.im/nodejs-101-package-promise-and-async 先回想一下 Sagase 的项目结构: lib/ cli.js ...