Tyvj P2044 ["扫地"杯III day2]旅游景点
Posted ZlycerQan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tyvj P2044 ["扫地"杯III day2]旅游景点相关的知识,希望对你有一定的参考价值。
二次联通门 : Tyvj P2044 ["扫地"杯III day2]旅游景点
/* Tyvj P2044 ["扫地"杯III day2]旅游景点 并查集 先把大于K的点合并 再从头扫一遍 若当前边的两边不在同一个集合就合并 否则就割掉这条边 */ #include <cstdio> #include <iostream> const int BUF = 12312313; char Buf[BUF], *buf = Buf; inline void read (int &now) { for (now = 0; !isdigit (*buf); ++ buf); for (; isdigit (*buf); now = now * 10 + *buf - ‘0‘, ++ buf); } #define Max 100009 struct E { int u, v; }; int f[Max]; E e[Max << 1]; int Find (int x) { return f[x] == x ? x : f[x] = Find (f[x]); } int main (int argc, char *argv[]) { freopen ("1.in", "r", stdin); fread (buf, 1, BUF, stdin); int N, M, K, x, y, Answer = 0; register int i, j; read (N), read (M), read (K); for (i = 1; i <= N; ++ i) f[i] = i; for (i = 1; i <= M; ++ i) { read (e[i].u), read (e[i].v); if (e[i].u > K && e[i].v > K) { x = Find (e[i].u), y = Find (e[i].v); f[x] = f[y]; } } for (i = 1; i <= M; ++ i) { if (e[i].u > K && e[i].v > K) continue; x = Find (e[i].u), y = Find (e[i].v); if (x != y) f[x] = y; else ++ Answer; } printf ("%d", Answer); return 0; }
以上是关于Tyvj P2044 ["扫地"杯III day2]旅游景点的主要内容,如果未能解决你的问题,请参考以下文章