标签:联通 http tar printf pen include logs targe 一个
二次联通门 : 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]旅游景点
标签:联通 http tar printf pen include logs targe 一个
原文地址:http://www.cnblogs.com/ZlycerQan/p/7457319.html