C - Misha and Forest
来源:互联网 发布:大学生网络诈骗ppt 编辑:程序博客网 时间:2024/05/22 03:27
感觉CF的题都是蛮巧妙的,题里 的每一句话都不是白给的,
就像这道题, 他说图里没有环, 就说明了两点, 1 -> 一定有度为一的节点 2->所有度的和一定是偶数, 确sum/2就等于变数
然后我们可以从 度为1 的节点入手。 它的sv一定是他临近节点的序号, 通过这个我们可以慢慢把所有节点的边都找出来
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
using namespace std;
#define MAXN 111111
#define LL long long
struct node
{
int id, deg, s;
}sta[MAXN];
queue<node> que;
int main()
{
int n;
scanf("%d",&n);
LL sum = 0;
for(int i = 0 ; i < n ; i++)
{
sta[i].id = i;
scanf("%d %d",&sta[i].deg, &sta[i].s);
if(sta[i].deg == 1)
que.push(sta[i]);
sum += (LL)sta[i].deg;
}
printf("%d\n",sum/2);
while(!que.empty())
{
node tem = que.front();
que.pop();
//这里要注意不能写成tem.deg因为队列里的元素的度是没更改之前的度, 我们要看的是更改之后的这时
//sta[i].id映射就发挥作用了
if(sta[tem.id].deg != 1)
continue;
printf("%d %d\n",tem.id, tem.s);
//x^x = 0 ,0^x = x 所以这一步相当于把当前节点对其临近节点的影响删除
sta[tem.s].s ^= tem.id;
if(--sta[tem.s].deg == 1)
que.push(sta[tem.s]);
}
return 0;
}0;
}
0 0
- C - Misha and Forest
- CodeForces 501C Misha and Forest
- Codeforces 501C - Misha and Forest (机智)
- Codeforces Round #285 C. Misha and Forest
- CodeFroces # 285 DIV2 C. Misha and Forest
- codeforce #501 c Misha and Forest
- 【codeforces 501 C Misha and Forest】
- CodeForces 501C Misha and Forest
- codeforces 501 C. Misha and Forest (思维)
- Misha and Forest CodeForces
- codeforces 501C Misha and Forest(思维题)
- Codeforces Round #285 (Div. 2) C. Misha and Forest
- Codeforces Round #285 (Div. 2) C - Misha and Forest
- Codeforces #285 C Misha and Forest 队列维护 解题报告
- Codeforces Round #285 (Div. 2) C. Misha and Forest
- Codeforces Round #285 (Div. 2)C. Misha and Forest
- codeforces#285--C - Misha and Forest(拓扑排序变形)
- CF 285div2 c题Misha and Forest
- 浅谈java的注解
- 解决EditText跟ScrollView滑动冲突
- qtcreator开发环境中如何配置交叉编译环境
- ScrollView加载完数据后自动滑动到底部
- Android笔记使用ContentResolver操作ContentProvider中的数据
- C - Misha and Forest
- 用shape结合selector实现点击效果
- thinphp支持nginx
- 滤波的概念和作用(滤波器、掩模、核、模板、窗口是一个意思)
- ora-02085的解决:Database Link与GLOBAL_NAMES参数
- JavaScript浏览器兼容问题
- 前端基础
- GitHub开源组件集锦
- DuplicateHandle 伪句柄 与 实句柄的应用