Monday, December 11, 2023
HomeSoftware DevelopmentDiscover two integers such that not less than one exists in every...

# Discover two integers such that not less than one exists in every given Pair

` `

`def` `verify(x, y, arr, n):`

` `

`    `

`    ``for` `i ``in` `vary``(``1``, n):`

`        ``if` `arr[i][``0``] ``=``=` `y ``or` `arr[i][``1``] ``=``=` `y `

`                ``or` `arr[i][``0``] ``=``=` `x ``or` `arr[i][``1``] ``=``=` `x:`

`            ``proceed`

`        ``else``:`

` `

`            `

`            `

`            ``return` `True`

`    ``return` `False`

` `

` `

`def` `findIndex(x, arr, n):`

`    ``for` `i ``in` `vary``(``1``, n):`

`        ``if` `arr[i][``0``] !``=` `x ``and` `arr[i][``1``] !``=` `x:`

`            ``return` `i`

`    ``return` `n`

` `

` `

`def` `discover(a, n):`

`    ``x ``=` `a[``0``][``0``]`

`    ``okay ``=` `findIndex(x, a, n)`

` `

`    `

`    ``if` `okay >``=` `n:`

`        ``return` `'YES'`

`    ``y ``=` `a[k][``0``]`

`    ``flag ``=` `0`

` `

`    `

`    ``if` `verify(x, y, a, n):`

` `

`        `

`        ``y ``=` `a[k][``1``]`

` `

`        `

`        ``if` `verify(x, y, a, n):`

` `

`            `

`            ``x ``=` `a[``0``][``1``]`

`            ``okay ``=` `findIndex(x, a, n)`

`            ``if` `okay >``=` `n:`

`                ``return` `'YES'`

` `

`            `

`            ``y ``=` `a[k][``0``]`

`            ``if` `verify(x, y, a, n):`

` `

`                `

`                ``y ``=` `a[k][``1``]`

`                ``if` `verify(x, y, a, n):`

`                    ``return` `'NO'`

`    ``return` `'YES'`

` `

` `

`if` `__name__ ``=``=` `'__main__'``:`

`    ``N ``=` `6`

`    ``M ``=` `5`

`    ``arr ``=` `[[``2``, ``3``], [``2``, ``4``], [``2``, ``5``], [``3``, ``4``], [``3``, ``5``], [``4``, ``5``]]`

` `

`    `

`    ``print``(discover(arr, N))`

RELATED ARTICLES