图论/位运算 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, ...
随机推荐
- 聊聊高并发(四十)解析java.util.concurrent各个组件(十六) ThreadPoolExecutor源代码分析
ThreadPoolExecutor是Executor运行框架最重要的一个实现类.提供了线程池管理和任务管理是两个最主要的能力.这篇通过分析ThreadPoolExecutor的源代码来看看怎样设计和 ...
- 【APUE】进程间通信之FIFO
FIFO也称为有名管道,它是一种文件类型,是半双工的.FIFO简单理解,就是它能把两个不相关的进程联系起来,FIFO就像一个公共通道,解决了不同进程之间的“代沟”.普通的无名管道只能让相关的进程进行沟 ...
- 【转】nginx 和 php-fpm 通信使用unix socket还是TCP,及其配置
原文: http://blog.csdn.net/pcyph/article/details/46513521 -------------------------------------------- ...
- linux迁移至固态硬盘全过程
自从台式机上用上固态硬盘后,就再也受不了笔记本上的5400转的机械硬盘了,所以这次又买了块固态硬盘打算装到笔记本上. 笔记本里装的是Ubuntu 14.04 + Win7双系统,Win7主要偶尔运行一 ...
- USB多重系統 - 開機碟工具 – WinSetupFromUSB
WinSetupFromUSB下載與安裝 讓USB磁碟擁有多重開機的功能,WinSetupFromUSB有著提軟體和硬體的高相容性. [官方網頁]:http://www.winsetupfromusb ...
- UML视频总结
"RUP 4+1"视图 学习UML我们就必须先了解这"RUP 4+1"视图,它是架构设计的结构标准,例如以下图所看到的. watermark/2/text/aH ...
- AIDL/IPC Android AIDL/IPC 进程通信机制——超具体解说及使用方法案例剖析(播放器)
首先引申下AIDL.什么是AIDL呢?IPC? ------ Designing a Remote Interface Using AIDL 通常情况下,我们在同一进程内会使用Binder.Broad ...
- Windows7 64bits下安装TensorFlow GPU版本(图文详解)
不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...
- 6 使用Ionic开发天气应用
简介:本节课我们会制作一款天气应用,这款应用允许用户查看当前的天气情况.天气预报以及地点收藏,在模态框内显示日出和日落的数据,使用分页滚动面板显示天气信息,使用侧滑菜单实现导航. 6.1 项目配置 环 ...
- 2016/05/05 smarty ① 登录 ②主页面 ③删除 ④让缩略信息显示完整 (补:增加 修改 )
共 八个页面 ①login.php <?php include("init.inc.php"); $smarty->display("login.html& ...