O46
Is Graph Bipartite?
Problem Statement & Objective
There is an undirected graph with n nodes. Return True if and only if it is bipartite.
Function Signature (Python)
is_graph_bipartite(graph: list[list[int]]) -> boolInput & Output Contract
Output Rule:True veya False.
System Constraints
n == grafik.length
1 <= n <= 100
0 <= grafik[i].length < n
Kendine kenar veya çift kenar yokturExample Execution Walkthrough
grafik = [[1, 3], [0, 2], [1, 3], [0, 2]] (kare 4'lü halka) -> True
grafik = [[1, 2, 3], [0, 2], [0, 1, 3], [0, 2]] (üçgen içerir) -> FalseExample Test Scenarios (3)
Example 1: 4'lü Döngü (Çift)
Input:
[[[1,3],[0,2],[1,3],[0,2]]]Expected Output:
trueExample 2: Tek Uzunluklu Döngü
Input:
[[[1,2,3],[0,2],[0,1,3],[0,2]]]Expected Output:
falseExample 3: Kenarsız
Input:
[[[]]]Expected Output:
true