【codevs 1069】关押罪犯
2016-10-30 00:00
316 查看
贪心
按影响排序
然后恩恩
如果same(x,y +n),说明x和y不在同一个监狱里
如果在合并之前,已经same(x,y)就输出答案
按影响排序
然后恩恩
如果same(x,y +n),说明x和y不在同一个监狱里
如果在合并之前,已经same(x,y)就输出答案
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 200000 + 5; int n,m,p; struct ChouHen { int f,t,v; bool operator < (const ChouHen &b)const { return v > b.v; } }ch[MAXN]; int fa[MAXN]; int rank[MAXN]; void init() { for(int i = 0;i <= n + n;i ++) fa[i] = i; memset(rank,0,sizeof(rank)); return; } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int x,int y) { x = find(x); y = find(y); if(rank[x] > rank[y]) swap(x,y); fa[x] = y; if(rank[x] == rank[y]) rank[y] ++; return; } bool same(int x,int y) { return find(x) == find(y); } int f,t; int main() { scanf("%d %d",&n,&m); init(); for(int i = 1;i <= m;i ++) scanf("%d %d %d",&ch[i].f,&ch[i].t,&ch[i].v); sort(ch + 1,ch + m + 1); for(int i = 1;i <= m;i ++) { if(same(ch[i].f,ch[i].t)) { printf("%d\n",ch[i].v); return 0; } merge(ch[i].f,ch[i].t + n); merge(ch[i].t,ch[i].f + n); } puts("0"); return 0; }
相关文章推荐
- Codevs 1069 关押罪犯 2010年NOIP全国联赛提高组
- Codevs 1069 关押罪犯
- codevs1069 关押罪犯 贪心+并查集
- CODEVS 1069关押罪犯
- NOIP2010提高组] CODEVS 1069 关押罪犯(并查集)
- codevs 1069 [NOIP2010] 关押罪犯 二分+二分图染色
- 【codevs 1069】关押罪犯
- NOIP2010 Codevs 1069 关押罪犯 [并查集] [二分图判定]
- 【codevs 1069】关押罪犯
- [codevs 1069 关押罪犯] [NOIP2010提高T3]
- CODEVS 1069 关押罪犯
- codevs 1069 关押罪犯
- 关押罪犯 codevs 1069(整理:加权并查集?+虚点并查集+二分图染色)
- Codevs-1069 关押罪犯
- 【codevs 1069】关押罪犯
- 【codevs】1069 关押罪犯
- 洛谷 P1525 关押罪犯==codevs 1069 关押罪犯[NOIP 2010]
- 【noip2010】codevs 1069 关押罪犯(二分+BFS染色||并查集)
- 并查集补集作法 codevs 1069 关押罪犯
- wikioi 1069 关押罪犯