# You are given an undirected graph with NN nodes (numbered 11 through NN). For each valid ii, the ii-th node has a weight WiWi. Also, for each pair of nodes ii and jj, there is an edge connecting these nodes if j−i≠Wj−Wij−i≠Wj−Wi. Find the number of connected components in this graph.- You are given an undirected graph with NN nodes (numbered 11 through NN). For each valid ii, the ii-th node has a weight WiWi. Also, for each pair of nodes ii and jj, there is an edge connecting these nodes if j−i≠Wj−Wij−i≠Wj−Wi. Find the number of connected components in this graph.

You are given an undirected graph with NN nodes (numbered 11 through NN). For each valid ii, the ii-th node has a weight WiWi. Also, for each pair of nodes ii and jj, there is an edge connecting these nodes if jiWjWij−i≠Wj−Wi.

Find the number of connected components in this graph.

For each test case, print a single line containing one integer — the number of connected components in the graph.

Example case 1: For i=1i=1 and j=2j=2, we have 21=212−1=2−1, therefore there are no edges in the graph and there are two connected components.

Example case 2: For i=1i=1 and j=2j=2, we have 21122−1≠1−2, therefore there is an edge between 11 and 22, the graph is connected, so there is only one connected component.

5★angeshs

25-08-2021

0.5 secs

50000 Bytes

CPP14, C, JAVA, PYTH 3.6, CPP17, PYTH, PYP3, CS2, ADA, PYPY, TEXT, PAS fpc, NODEJS, RUBY, PHP, GO, HASK, TCL, PERL, SCALA, LUA, kotlin, BASH, JS, LISP sbcl, rust, PAS gpc, BF, CLOJ, R, D, CAML, FORT, ASM, swift, FS, WSPC, LISP clisp, SQL, SCM guile, PERL6, ERL, CLPS, ICK, NICE, PRLG, ICON, COB, SCM chicken, PIKE, SCM qobi, ST, SQLQ, NEM

You are given an undirected graph with NN nodes (numbered 11 through NN). For each valid ii, the ii-th node has a weight WiWi. Also, for each pair of nodes ii and jj, there is an edge connecting these nodes if j−i≠Wj−Wij−i≠Wj−Wi. Find the number of connected components in this graph.