题目传送门

 /*
题意:给出无向无环图,每一个点的度数和相邻点的异或和(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 #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  6. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

  7. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  8. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  9. 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift

    题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...

随机推荐

  1. sublime text 3(Build 3103)最新注冊码

    原来注冊过的sublime text 3近期更新了.没想到原来的注冊码就失效了,只是我找到了最新的注冊码(Build 3103),与大家分享一下(第一个亲測可用). -– BEGIN LICENSE ...

  2. java File_encoding属性

    今天给客户发版本号,突然发现报表导出内容为空,大小0字节.感到很奇怪,由于开发的时候都好好的,打包出来怎么会出现异常. 细看才后发现是 file_encoding这个java系统属性编码方式设置导致的 ...

  3. 工作总结 js 选择器选择多条元素 支持一起设置他们属性 $("#edumes input[type='radio']").prop("checked", false);

    $("#edumes input[type='radio']").prop("checked", false); $("#edumes input[t ...

  4. oracle官方文档_查看初始化參数(举例)

    原创作品,出自 "深蓝的blog" 博客.深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46864217 记录 ...

  5. MJRefresh实现刷新(使用它的Block方法)

    MJRefresh实现刷新(使用它的Block方法)   // // YFMVCPostListViewController.m // iOS122 // // Created by 颜风 on 15 ...

  6. VMware 虚拟机添加硬盘以及为新添加的硬盘创建Samba共享 (转)

    一.为VMware虚拟机添加硬盘 1. 首先在VMware虚拟机的VM->Setting子菜单中为虚拟机添加一块15G大小的SCSI类型的硬盘(注意:如果原来为IDE硬盘,SCSI类型的硬盘可能 ...

  7. vmware10上安装mac os 10.9

    来源地址:http://dtbuluo.com/blog/archives/350 序言: 前几天跟朋友开玩笑说,要不我们一起来学习一下swift编程语言吧~我们就抱着玩玩的态度,没有想过要做出什么优 ...

  8. VS创建Web项目提示配置IISExpress失败

    开发服务器VS2013,新建Web项目提示: 打开Web项目提示: 解决方法:控制面板,找到IISExpress,右键 选择修复,解决问题..

  9. asp.net 实现搜索站内搜索功能

    首先有index和search 两个页面 index页面中有textbox1和button1两个控件 双击button1控件添加代码: protected void Button1_Click(obj ...

  10. JSON: Circular Dependency Errors

    If you’re using Object Relational Mapping frameworks like Hibernate, and are using the bi-directiona ...