Last active
April 30, 2019 14:39
-
-
Save sofhiasouza/9cd8453858df16b7bf943ae9b8a4fd5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define MAXN 100010 | |
using namespace std; | |
int n, m, pontos[MAXN], comp[MAXN]; | |
inline int find(int x) | |
{ | |
if(comp[x] == x) return x; | |
return comp[x] = find(comp[x]); | |
} | |
inline void join(int a, int b) | |
{ | |
comp[find(a)] = find(b); | |
} | |
int main() | |
{ | |
cin >> n >> m; | |
for(int i = 0 ; i < n ; i++) | |
{ | |
cin >> pontos[i]; | |
comp[i] = i; | |
} | |
int cont = 0; | |
for(int i = 0 ; i < m ; i++) | |
{ | |
int q, a, b; | |
cin >> q >> a >> b; | |
if(q == 1) | |
{ | |
pontos[find(b)] += pontos[find(a)]; | |
join(a, b); | |
} | |
else | |
{ | |
if(find(1) == find(a) and pontos[find(a)] > pontos[find(b)]) cont++; | |
else if(comp[1] == comp[b] and pontos[comp[b]] > pontos[comp[a]]) cont++; | |
} | |
} | |
cout << cont << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment