我们首先发现有如下性质:

我们不妨先随机定向边,那么我们发现无论我们如何翻转边。

都会对其两端的点,造成 \(2 / 4\) 的影响,所以我们发现如果一个点其和他相连的所有边权和为偶数,则我们不能调整其为好点。

那么我们自然的思考,是否能够构造一种方案使得所有边权和为奇数的都可以成为好点。

我们下列先给出一个方案再进行一个证明。

我们对所有的奇度点都与一个虚点相连一条边权为 \(1\) 的虚边。

我们知道一条边会同时改变两点的度数奇偶情况,即奇度数点为偶数。

所以我们操作之后一定所有点都是偶数,那这图是一个欧拉回路。

考虑我们在进行欧拉回路的遍历时,我们首先满足让出边让入边的边权相等,否则使用另一边。

考虑对边权为偶数的我们可以任意定向,那我们不进行考虑。

那么我们考虑边权为奇数的,那么有两种情况。

一:奇数条边权为 \(1\) 的边,奇数条的边权边权为 \(2\) 的边。

此种情况,我们按我们的操作的一定会最后只会抵消到只剩一条边权为 \(1\) 的和一条边权为 \(2\) 的边。

那么其为好点。

一:奇数条边权为 \(1\) 的边,偶数条的边权边权为 \(2\) 的边。

此种情况,我们按我们的操作的一定会最后只会抵消到只剩一条边权为 \(1\)。

那么其为好点。

所以我们只要按照这种操作即可使得所有边权和的奇数的点都是好点。

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<list>
#define ll lonng long
#define N 600005 bool begin; int n,m; int to[N];
int from[N]; int sum[N]; int fans,ans[N]; int vis[N]; int cnt[N]; std::vector<int>Q[N][3];//边权为1,边权为2
int head[N][3]; int dfn[N]; bool end; inline void dfs(int u,int now){
// std::cout<<u<<" "<<now<<std::endl;
// std::cout<<"rest"<<head[u][now]<<" "<<head[u][3 - now]<<std::endl;
int fnow = now;
while(!(Q[u][now].size() <= head[u][now] && Q[u][3 - now].size() <= head[u][3 - now])){
dfn[u] = 1;
while(head[u][now] < Q[u][now].size() && vis[Q[u][now][head[u][now]]])
head[u][now] ++;
while(head[u][3 - now] < Q[u][3 - now].size() && vis[Q[u][3 - now][head[u][3 - now]]])
head[u][3 - now] ++;
if(Q[u][now].size() != head[u][now]){
ans[Q[u][now][head[u][now]]] = (u == from[Q[u][now][head[u][now]]]) + 1;
vis[Q[u][now][head[u][now]]] = 1;
// std::cout<<"("<<u<<"->"<<" "<<(to[Q[u][now][head[u][now]]] - u)<<")"<<std::endl;
// std::cout<<Q[u][now].front()<<std::endl;
dfs(to[Q[u][now][head[u][now]]] - u,now);
head[u][now] ++ ;
}else{
now = 3 - now;
if(Q[u][now].size() != head[u][now]){
ans[Q[u][now][head[u][now]]] = (u == from[Q[u][now][head[u][now]]]) + 1;
vis[Q[u][now][head[u][now]]] = 1;
// std::cout<<"("<<u<<"->"<<" "<<(to[Q[u][now][head[u][now]]] - u)<<")"<<std::endl;
// std::cout<<Q[u][now].front()<<std::endl;
dfs(to[Q[u][now][head[u][now]]] - u,now);
head[u][now] ++ ;
}
}
now = fnow;
}
return ;
} int main(){
// std::cout<<(&end - &begin) / 1024 / 1024<<std::endl;
scanf("%d%d",&n,&m);
for(int i = 1;i <= m;++i){
int x,y,p;
scanf("%d%d%d",&x,&y,&p);
to[i] = x + y;
cnt[x] ++ ;
cnt[y] ++ ;
from[i] = x;
sum[x] += p;
sum[y] += p;
Q[x][p].push_back(i);
Q[y][p].push_back(i);
}
int mcnt = m;
for(int i = 1;i <= n;++i){
if(sum[i] & 1)
fans ++ ;
if(cnt[i] & 1){
int x = n + 1;
int y = i;
int p = 1;
to[++mcnt] = x + y;
from[mcnt] = x;
Q[x][p].push_back(mcnt);
Q[y][p].push_back(mcnt);
}
}
for(int i = 1;i <= n + 1;++i)
if(!dfn[i])
dfs(i,1);
std::cout<<fans<<std::endl;
for(int i = 1;i <= m;++i)
std::cout<<(ans[i]);
return 0;
}

CF1610F F. Mashtali: a Space Oddysey的更多相关文章

  1. 列表屏幕(List Screen)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. ES5基础之正则表达式02:范围类、预定义类和边界字符

    1.范围类 //元字符 /* * 正则表达式由两种基本字符类型组成 * 1.原义文本字符:例如123abc * 2.元字符:元字符是在正则表达式中有特殊含义的非字母字符 */ //常见特殊符号:. * ...

  3. mac 系统通用快捷键(mac 下的应用多数会往这些标准看齐)(转:http://yang3wei.github.io/blog/2013/02/08/chen-ni-yu-mac-chen-ni-yu-xcode/)

    command + w: 关闭当前窗口 command + q: 退出程序 (Google Chrome 有点奇葩,按下之后还需要hold 那么一小会儿才能退出) command + m: 最小化当前 ...

  4. 获取windows磁盘的可用空间函数

    <?php /* *获取某个磁盘的剩余空间 *$param 关联数组,下标是哪个盘,单位,可以是B,KB,MB,GB *可以设置获取多个磁盘,例如:array('C'=>'KB','D'= ...

  5. web前端开发工具HBuilder使用技巧之快捷键

    /*注:本教程针对HBuilder5.0.0,制作日期2014-12-31*/ 创建HTML结构: h 8 (敲h激活代码块列表,按8选择第8个项目,即HTML代码块,或者敲h t Enter) 中途 ...

  6. Half Wavelength Dipole Antenna

    Reference : 1. wikipedia The dipole antenna is the simplest and most widely used class of antenna.It ...

  7. ocp 1Z0-042 61-120题解析

    61. View the Exhibit.Which statement regarding the dept and emp tables is true?A) When you delete a ...

  8. hbuilder工具快捷键 http://www.qq210.com/shoutu/android

    http://www.qq210.com/shoutu/android 创建HTML结构: h 8 (敲h激活代码块列表,按8选择第8个项目,即HTML代码块,或者敲h t Enter)中途换行: ' ...

  9. windbg命令详解

      DLL 该扩展仅在内核模式下使用,即使它是在Ext.dll中的. Windows NT 4.0 Ext.dll Windows 2000 Ext.dll Windows XP和之后 Ext.dll ...

随机推荐

  1. 初学python-day11 函数3

    函数 1. global关键字 修改全局变量,声明函数内外使用同一个变量 示例: 1 name = 'xiaoming' 2 3 def test(): 4 global name 5 name = ...

  2. 【UE4】读写 Texture 数据

    创建texture 方式一 void AActor_Assignment2::TextureFromImage_Internal( const TArray<FColor>& Sr ...

  3. pagelayout中边界灵敏度动画时间kv

    <PageLayoutWidget>: # 默认是50dp 设置边界 border:'100dp' # 默认哪一页 page:2 # 设置翻页动画及持续时间 anim_kwargs:{'d ...

  4. logstash的安装和简单使用

    logstash的安装和简单使用 一.安装 1.下载并解压 2.logstash 一些命令行参数 1.查看帮助信息 2.加载指定pipeline文件路径 3.检测配置文件语法是否有错误 4.热加载pi ...

  5. Machine learning(1-Introduction)

    1.What is machine learning Field of study that gives computers the ability to learn without being ex ...

  6. Unmount and run xfs_repair

    参考连接:https://blog.csdn.net/qq_35022803/article/details/109287086 如故障图所示,sda3出现问题, 下面的解决办法: 解决办法: 原因: ...

  7. php swoft redis 发布和订阅

    //订阅 public function subscribe() { /* @var \Swoft\Redis\Redis $redis */ $redis = App::getBean(\Swoft ...

  8. prometheus(7)之数据类型与PromQL语法

    Prometheus的四种数据类型 counter (只增不减 计数) Gauge (常规数值 可变化大小) histogram (柱状图 小于上边界的 总数与次数) summary (分位数  小于 ...

  9. k8s入坑之路(11)kubernetes服务发现

    kubernetes访问场景 1.集群内部访问 2.集群内部访问外部 3.集群外部访问内部 1.集群内部访问 1.pod之间直接ip通讯(利用calico通过路由表经过三层将ip流量转发)由于容器之间 ...

  10. 跟着老猫来搞GO,基础进阶

    回顾一下上一篇博客,主要是和大家分享了GO语言的基础语法,其中包含变量定义,基本类型,条件语句,循环语句.那本篇呢就开始和大家同步一下GO语言基础的进阶. 函数的定义 上次其实在很多的DEMO中已经写 ...