题目传送门

 /*
题意:给出无向无环图,每一个点的度数和相邻点的异或和(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的更多相关文章

  1. 水题 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  2. 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 ...

  3. 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 ...

  4. 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles

    题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...

  5. Codeforces Round #285 (Div. 1) B - Misha and Permutations Summation 康拓展开+平衡树

    思路:很裸的康拓展开.. 我的平衡树居然跑的比树状数组+二分还慢.. #include<bits/stdc++.h> #define LL long long #define fi fir ...

  6. 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 ...

  7. 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 ...

  8. CodeForces Round #285 Div.2

    C.Misha and Forest (图论 BFS) 比赛进行了一半才想起来有场CF没打,=_=|| 前两道题快速切掉,C题一直卡没什么好的思路 憋了几天,忍不住偷偷瞄了一下别人AC的代码,发现我题 ...

  9. Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组

    题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...

随机推荐

  1. 电脑控制手机的另一选择——android vnc server

    近来发现的Android上的原生VNC Server,就是说只要手机上安装并运行这个软件,即可实现电脑上查看并控制手机了. 首先是手机端. 1)下载androidvncserver: http://c ...

  2. centos 安装python2.7

    安装pip sudo yum -y install epel-release sudo yum -y install python-pip 下载解压Python-2.7.3 #wget http:// ...

  3. POJ2573 Bridge 经典的过桥问题

    曾经遇到过类似的.纪念一下!这题同一时候也是  ZOJ1877.经典的过桥问题 是有个博客解说的非常好的 戳这里 挺久曾经.遇到过一个基本一样的,那个题目仅仅要求求出 最短时间就可以,如今还有过桥的过 ...

  4. 解决pycharm下安装reportLab报错的问题

    在利用pycharm中自带的第三方安装工具安装reportLab时提示安装失败.失败的原因是缺失第三方扩展包.经过查阅查阅资料了解到一些python的第三方扩展包是需要python-dev支持的.我装 ...

  5. python各进制、字节串间的转换

    >>> i = 13 >>> bin(i) '0b1101' >>> oct(i) '0o15' >>> hex(i) '0xd ...

  6. ASP.NET MVC3 自定义编辑模版

    在View中显示Model中的各字段,默认是使用htmlhelper的EditorFor方法,在界面上显示的文本框.而使用EditorTemplates可在View上为特定字段显示自定义的界面.比如购 ...

  7. SE11 数据表中 日志数据更改 勾选的作用

        [园工]HF-abap-Rainy(574570549)  11:10:12这个有啥作用,勾上了怎么查修改日志呢,[园丁]SH-CRM-ALEX(8738890)  11:13:53SCU3[ ...

  8. Linux 打包classes

    进入项目后 tar -zcvf ~/${HOSTNAME}-${PWD##*/}-$(date +%Y-%m-%d)-classes.tar.gz webapps/ROOT/WEB-INF/class ...

  9. bzoj1858 [Scoi2010]序列操作——线段树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1858 线段树...调了一个上午...(后面带 // 的都是改出来的) lazy 标记的下放好 ...

  10. hdu3092

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3092 题目描述:将一个数拆分成几个数之和,问这几个数能得到的最大的最小公倍数模上给定的一个数是多少? ...