UVALive 3644 X-Plosives
来源:互联网 发布:类图用什么软件画 编辑:程序博客网 时间:2024/06/06 02:25
并查集。
给出若干个组合a b,如果a和b属于同一集合则拒绝,输出拒绝的次数。
为啥提到被拒绝总觉得苦逼呢,唉,屌丝程序员的春天在哪里啊
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<queue>#include<cmath>///LOOP#define REP(i, n) for(int i = 0; i < n; i++)#define FF(i, a, b) for(int i = a; i < b; i++)#define FFF(i, a, b) for(int i = a; i <= b; i++)#define FD(i, a, b) for(int i = a - 1; i >= b; i--)#define FDD(i, a, b) for(int i = a; i >= b; i--)///INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RFI(n) scanf("%lf", &n)#define RFII(n, m) scanf("%lf%lf", &n, &m)#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)#define RS(s) scanf("%s", s)///OUTPUT#define PN printf("\n")#define PI(n) printf("%d\n", n)#define PIS(n) printf("%d ", n)#define PS(s) printf("%s\n", s)#define PSS(s) printf("%s ", n)///OTHER#define pb(x) push_back(x)#define CLR(a, b) memset(a, b, sizeof(a))#define CPY(a, b) memcpy(a, b, sizeof(b))#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}using namespace std;typedef long long LL;typedef pair<int, int> P;const int MOD = 100000000;const int INFI = 1e9 * 2;const LL LINFI = 1e17;const double eps = 1e-6;const double pi = acos(-1.0);const int N = 111111;const int M = 11;const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int f[N];int find(int x){return x == f[x] ? x : f[x] = find(f[x]);}int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int a, b, x, y, ans; while(RI(a) != EOF) { ans = 0; REP(i, N)f[i] = i; while(a != -1) { RI(b); x = find(a); y = find(b); if(x == y)ans++; else f[x] = y; RI(a); } PI(ans); } return 0;}
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- uvalive 3644 X-Plosives
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- 【暑假】[实用数据结构]UVAlive 3644 X-Plosives
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- UVALive(LA) 3644 X-Plosives (并查集)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives(简单并查集)
- UVALive 3644 X-Plosives (并查集)
- X-Plosives +uvalive+并查集+水题
- UVA 11997 K Smallest Sums
- 一个疑问
- java内存泄漏的定位与分析
- Java线程范围变量——ThreadLocal的模拟和解释
- CentOS查看CPU、内存、网络流量和磁盘 I/O【详细】
- UVALive 3644 X-Plosives
- UVALive 3027 Corporative Network
- RobotFramework+Selenium2环境搭建与入门实例
- eclipse hadoop开发环境配置
- Codeforces Round #196 (Div. 2) A. Puzzles
- 【黑马程序员】java I/O流浅谈
- Codeforces Round #196 (Div. 2) B. Routine Problem
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- QT中新建的类继承QWidget和QMainWindow的不同之处