题意

有n个点,代号分别为0到n-1,然后第i个点有di个相连点,与i 相连的点的XOR sum 为si,求所有的边。

分析

知识:a^b^a=b,a^b^b=a.

把相连点为1的i存进队列,i的唯一相连点就是S。

然后得到一条边i到s,对i的相连点S,d--,s^=i,就相当于去掉i这个点。

然后再判断S的相连点d是不是1,是1则进入队列。

直到队列为空。

代码

#include<cstdio>
#include<algorithm>
#include<queue>
#define N 100005 using namespace std; int n,b;
int ex[N],ey[N],d[N],s[N]; queue<int> q; int main()
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d%d",&d[i],&s[i]);
if(d[i]==)q.push(i);
} while(!q.empty())
{
int i=q.front();
q.pop();
if(d[i]==)
{
ex[b]=i;
ey[b]=s[i];
b++; s[s[i]]^=i;
d[s[i]]--;
if(d[s[i]]==) q.push(s[i]);
}
} printf("%d\n",b);
for(int i=; i<b; i++)
printf("%d %d\n",ex[i],ey[i]);
return ;
}

  

【CodeForces 504A】Misha and Forest的更多相关文章

  1. 【Codeforces 501C】Misha and Forest

    [链接] 我是链接,点我呀:) [题意] 给你一棵树 但是每个节点只告诉你出度个数 以及所有和它相连的点的异或和. 让你还原这棵树 [题解] 叶子节点的话,他所有节点的异或和就是它那唯一的一个爸爸 因 ...

  2. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 501D】Misha and Permutations Summation

    [题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...

  4. 【CodeForces - 501B 】Misha and Changing Handles(map)

    Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description  神秘的三角洲里还有一个传说 ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. codeforces 711C C. Coloring Trees(dp)

    题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. HDU 4409 Family Name List --乱搞、LCA

    题意: 给出一些名字,名字间有父子关系,有三种操作: 1.按祖先到后代,兄弟间按字典序由小到大排序,然后输出 2.求某个节点的兄弟节点有多少个,包括自己(注意,根节点的兄弟节点是1) 3.求节点a和b ...

  3. Android应用中菜单(Menu)的位置显示问题

    http://blog.csdn.net/songjinshi/article/details/17381245 注意:为了适配4.0菜单能够横向显示,建议在activity中添加android:th ...

  4. VS2013中BOOST库的环境配置与使用

    &1 安装Boost 文件下载:链接:http://pan.baidu.com/s/1kUKaOFP 密码:auf2 解压之后放到你想安装的文件夹内,我的是在C:\Program Files\ ...

  5. 爬取熊猫TV,javascript,selenium,模拟点击

    from selenium import webdriver import csv def get_pages_numger(browser): res = browser.find_elements ...

  6. HTTP协议简介2

    几个相关的知识点: 客户端发送请求时,请求类型为GET与POST的主要差别是什么? 1.请求类型不同,一个为GET,一个为POST 2.当请求类型为GET时,请求的数据以参数的形式添加到url的后面, ...

  7. Google protocol buffer在windows下的编译

    在caffe框架中,使用的数据格式是google的 protocol buffer.对这个不了解,所以,想简单学习一下.简单来说,Protocol Buffer 是一种轻便高效的结构化数据存储格式,可 ...

  8. LeetCode:Populating Next Right Pointers in Each Node I II

    LeetCode:Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeL ...

  9. Metasploit_01_信息搜集技术

    信息搜集技术 姓名: 谈愈敏 学号: 20135220 日期: 2016.9.7 攻击机:135220-V.BT5, msf 靶 机:135220-V.W2k3_Sploitable 一.实验过程概述 ...

  10. Linux内核分析——期末总结

    Linux内核学习总结 首先非常感谢网易云课堂这个平台,让我能够在课下学习,课上加强,体会翻转课堂的乐趣.孟宁老师的课程循序渐进,虽然偶尔我学习地不是很透彻,但能够在后续的课程中进一步巩固学习,更加深 ...