首页 > 其他分享 >CF553C Love Triangles

CF553C Love Triangles

时间:2023-10-16 18:34:59浏览次数:26  
标签:typedef Love int CF553C long include col Triangles define

很有意思的一个题,想了一会才发现解题的关键

首先我们注意到对于某个大小\(\ge 3\)的连通块,其实连通块内的所有边的颜色都会被已知的边唯一确定

而不同的连通块间的连边方式有两种,因此设连通块个数为\(tot\),最后的答案就是\(2^{tot-1}\)

但还要考虑判掉不合法的情况,注意到不管是\(111\)还是\(100\),从某个点沿着环走回这个点经过的\(1\)边数量都是奇数

那么很容易想到用染色来判断合法性,具体地,我们把\(1\)对应的边看作连接了两个颜色相同的点;\(0\)对应的边连接了两个颜色不同的点,然后看这个图是否可以黑白染色即可

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_set>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=100005,mod=1e9+7;
int n,m,x,y,z,tot,col[N]; vector <pi> v[N];
inline void DFS(CI now)
{
	for (auto [to,w]:v[now])
	if (!~col[to]) col[to]=col[now]^w,DFS(to); else
	if (col[to]!=(col[now]^w)) { puts("0"); exit(0); }
}
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (scanf("%d%d",&n,&m),i=1;i<=m;++i)
	scanf("%d%d%d",&x,&y,&z),z^=1,v[x].push_back(pi(y,z)),v[y].push_back(pi(x,z));
	for (memset(col,-1,sizeof(col)),i=1;i<=n;++i)
	if (!~col[i]) col[i]=0,DFS(i),++tot;
	int ans=1; for (i=1;i<tot;++i) ans=2LL*ans%mod;
	return printf("%d",ans),0;
}

标签:typedef,Love,int,CF553C,long,include,col,Triangles,define
From: https://www.cnblogs.com/cjjsb/p/17768061.html

相关文章

  • P9290 Luna likes Love 题解
    原题:[洛谷P9310]([P9310EGOI2021]LunalikesLove/卢娜爱磕cp-洛谷|计算机科学教育新生态(luogu.com.cn))题目大意给定一个长度为\(\large2n(n\leq10^5)\)的序列,序列中\(\large1\simn\)的每一个数都恰好出现两次。可进行两种操作:交换两个相邻的数的位置。......
  • [极客大挑战 2019]LoveSQL 1
    原理常规注入解题过程进入登录界面,还是使用万能登录试一试payload:1'or1=1#没想到成功了,说明字符型注入使用的'爆出的密码应该是MD5加密,爆破很麻烦,试试常规注入payload:1'orderby4#payload:1'orderby3#找出列项payload:1'unionselect1,database(),3#找出......
  • P5047 [Ynoi2019 模拟赛] Yuno loves sqrt technology II 题解
    Description给你一个长为\(n\)的排列,\(m\)次询问,每次查询一个区间的逆序对数,强制在线。link\(1\leqn,m\leq10^5\)。Solution考虑分块。首先如果\(l,r\)在同一个块内,可以对于每个块暴力二维前缀和预处理。如果\(l,r\)在不同的块内。设\(bel[l]=x,bel[r]=y\)。首......
  • F. Vasilije Loves Number Theory
    F.VasilijeLovesNumberTheory前提知识:d(n)表示数字n的正约数个数,gcd(a,b)表示a,b两者的最大公约数要点:问是否存在a,使得d(a*n)=n,gcd(n,a)=1,意思是n与a互质,则可得,d(a*n)=d(a)*d(n)=n则问题转化成n%d(n)==0?尽管d(n)<=1e9,但n可能很大,所以可以利用质因子来求点击查看......
  • 346_黑苹果Clover修改神器其一——设置自动倒计时
    这是一篇原发布于2020-02-0314:38:00得益小站的文章,备份在此处。前言这几日轶哥折腾黑苹果,安装过程倒是挺顺利,只不过这次的四叶草引导并没有自动倒计时功能。简单百度下,发现修改的方法挺简单,一起和轶哥来学习下吧![scodetype="yellow"]操作前请自行准备恢复U盘(推荐微PE),备份efi......
  • KingbaseES V8R3集群运维案例之---主库数据库服务down后failover切换详解
    案例说明:对KingbaseESV8R3集群,主库数据库服务down后,failover切换进行分析,详解其执行切换的过程,本案例可用于对KingbaseESV8R3集群failover故障的分析参考。适用版本:KingbaseESV8R3集群架构:node_id|hostname|port|status|lb_weight|role|select_cnt......
  • KingbaseES V8R3集群运维案例---failover切换故障分析
    案例说明:KingbaseESV8R3集群主库数据库服务重启后,failover切换失败,分析failover失败的具体原因。适用版本:KingbaseESV8R3一、集群架构node13----->主库(primary)node25----->管理备库(standby)node58----->备库(standby)二、故障现象1主2备集群,172.31.*......
  • Codeforces Round 811 (Div. 3) A. Everyone Loves to Sleep
    闹钟设有\(n\)个时间点,第\(i\)个时间为\((H_i,M_i)\)。在\(h,m\)时刻入睡,响铃必须起床,问能睡多久。使用\(set<pair<int,int>>\)存储闹铃时刻,然后在其中\(lower_{bound}\)到\(<first\geqh,second\geqm>\)的迭代器\(it\)。若\(it=end\),则\(it=begin......
  • BZOJ3309 DZY Loves Math
    题目大意对于正整数\(n\),定义\(f(n)\)为\(n\)所包含质因子的最大幂指数。例如\(f(1960)=f(2^3\times5^1\times7^2)=3\),\(f(10007)=1\),\(f(1)=0\)。给定正整数\(a,b\),求下式的值:\[\sum^{a}_{i=1}\sum^{b}_{j=1}f(\gcd(i,j))\]推导首先记\(n=\min(a,b),m=\max(a,b)......
  • JLR DOIP VCI SDD Pathfinder Interface: The Best Choice for Jaguar Land Rover Lov
    IfyouareaJaguarLandRover(JLR)enthusiast,youmustbefamiliarwiththeimportanceofhavingtherightdiagnostictoolathand.Inthisblogpost,wewilldiscusstheJLRDOIPVCISDDPathfinderInterfaceandwhyitstandsoutasthebestchoicefo......