当前位置: 首页 > news >正文

2024河南萌新联赛第五场 C小美想收集(并查集拓展域,2-sat)

题目链接


思路:

这题是并查集拓展域板题,而且并查集拓展域其实就是2-sat,虽然做法不同,但是思想是相通的,也可以用2-sat来做。

一个回忆可以看成在好回忆或在坏回忆里,两种选择。

code:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=2e5+5;
const int maxm=1e5+5;int n,m;struct edge{int u,v,w;edge(int u=0,int v=0,int w=0):u(u),v(v),w(w){};bool operator<(const edge x)const{return w>x.w;}
}e[maxm];int f[maxn<<1];
int findf(int x){return f[x]==x?x:f[x]=findf(f[x]);}
void merge(int x,int y){int fx=findf(x),fy=findf(y);f[fy]=fx;
}int main(){cin>>n>>m;for(int i=1;i<=m;i++)cin>>e[i].u>>e[i].v>>e[i].w;sort(e+1,e+m+1);for(int i=1;i<=(n<<1);i++)f[i]=i;for(int i=1;i<=m;i++){auto [u,v,w]=e[i];
//		printf("^^^%d %d %d\n",u,v,w);if(findf(u)!=findf(v)){//两者不在同一个集合 merge(u,v+n);merge(u+n,v);}else {printf("%d",w);break;}}return 0;
} 

http://www.mrgr.cn/news/6292.html

相关文章:

  • Python爬虫案例二:获取虎牙主播图片(动态网站)
  • Spring Boot实战:通过Spring Batch处理批量订单数据
  • UDP+TCP
  • 类别特征编码 ———特征工程
  • Unity 编辑器-UGUI拓展Button,一个和原Button一样按钮⭐
  • AI大模型日报#0820:DeepMind创始人访谈、阿里多模态mPLUG-Owl3、抱抱脸SOTA小模型
  • P1167 刷题
  • GIS空间数据库,基本概念
  • docker相关
  • 蛋托清洗机的优势特点以及维护和保养:
  • TCP的连接建立及报文段首部格式
  • Android CCodec Codec2 (三)C2Param - Ⅰ
  • C# Dictionary->ConcurrentDictionary和哈希表
  • 【速览】计算机网络(更新中)
  • 【Spring Boot】全局异常处理
  • 微信小程序:浮动按钮
  • jenkins 修改访问路径
  • node.js express创建本地服务以及使用pm2启动服务
  • 25届网安秋招面试之后台信息泄露
  • Nginx知识详解(理论+实战更易懂)