0

what's this mean

int find(int u) { return P[u] = P[u] == u ? u : find(P[u]); }

full code(c++) -it tell which number are connected.

   #include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5;

int n, m, k;
int P[N];

int find(int u) { return P[u] = P[u] == u ? u : find(P[u]); }

int main() {
    scanf("%d %d %d", &n, &m, &k);
    iota(P, P+N, 0);
    for(int i = 0, a, b; i < m; ++i) {
        scanf("%d %d", &a, &b);
        a = find(a), b = find(b);
        P[a] = b;
    }
    for(int i = 0, a, b; i < k; ++i) {
        scanf("%d %d", &a, &b);
        puts(find(a) == find(b) ? "yes" : "no");
    }
}

input- 3 2 3 1 2 2 1 2 3 3 1 1 2

out put- no no yes

hogpip
  • 1

1 Answers1

0

int find(int u) { return P[u] = P[u] == u ? u : find(P[u]); }

equal

int find(int u ) {
  if ( p[u] == u ) p[u] = u;
    else P[u] = find(P[u]);
  return P[u];
}

This is another way of writing

condition ? consequent : alternative
Itati
  • 193
  • 11
  • 3
    Right, but what does it _mean_? – Asteroids With Wings Jun 11 '20 at 16:43
  • What Atsteroids is trying to get you do do is explain the program behaviour the code is trying to express. What is that code doing? How does it solve the problem it's supposed to solve? What is the problem the code is supposed to solve? – user4581301 Jun 11 '20 at 17:05
  • @AsteroidsWithWings Oh, I misunderstood what he meant – Itati Jun 11 '20 at 17:17
  • @user4581301 Oh, I misunderstood what he meant. English is not my native language. – Itati Jun 11 '20 at 17:18
  • @Itati it's possible that all the questioner cares about is the syntax, but in general a discussion of syntax is of little use without discussing the behaviour the syntax is supposed to express. – user4581301 Jun 11 '20 at 17:41