{"id":22513623,"url":"https://github.com/emahtab/possible-bipartition","last_synced_at":"2026-02-06T07:33:35.453Z","repository":{"id":79525711,"uuid":"441350442","full_name":"eMahtab/possible-bipartition","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-24T03:02:23.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-27T07:30:58.318Z","etag":null,"topics":["bipartite-graph","breadth-first-search","graph","leetcode"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-12-24T02:57:10.000Z","updated_at":"2021-12-24T03:03:33.000Z","dependencies_parsed_at":"2023-05-10T17:30:50.110Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/possible-bipartition","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/possible-bipartition","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fpossible-bipartition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fpossible-bipartition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fpossible-bipartition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fpossible-bipartition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/possible-bipartition/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fpossible-bipartition/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29154323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bipartite-graph","breadth-first-search","graph","leetcode"],"created_at":"2024-12-07T03:13:46.383Z","updated_at":"2026-02-06T07:33:35.443Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Possible Bipartition\n## https://leetcode.com/problems/possible-bipartition\n\nWe want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.\n\nGiven the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split everyone into two groups in this way.\n\n \n```\nExample 1:\n\nInput: n = 4, dislikes = [[1,2],[1,3],[2,4]]\nOutput: true\nExplanation: group1 [1,4] and group2 [2,3].\n\nExample 2:\nInput: n = 3, dislikes = [[1,2],[1,3],[2,3]]\nOutput: false\n\nExample 3:\nInput: n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]\nOutput: false\n``` \n\n## Constraints:\n```\n1. 1 \u003c= n \u003c= 2000\n2. 0 \u003c= dislikes.length \u003c= 104\n3. dislikes[i].length == 2\n4. 1 \u003c= dislikes[i][j] \u003c= n\n5. ai \u003c bi\n6. All the pairs of dislikes are unique.\n```\n\n# Implementation : BFS\n```java\nclass Solution {\n    public boolean possibleBipartition(int n, int[][] dislikes) {\n        int[] visited = new int[n];\n        Arrays.fill(visited, -1);\n        Map\u003cInteger,List\u003cInteger\u003e\u003e graph = new HashMap\u003c\u003e();\n        for(int[] dislike : dislikes) {\n            int u = dislike[0] - 1;\n            int v = dislike[1] - 1;\n            graph.putIfAbsent(u, new ArrayList\u003cInteger\u003e());\n            graph.putIfAbsent(v, new ArrayList\u003cInteger\u003e());\n            graph.get(u).add(v);\n            graph.get(v).add(u);\n        }\n        for(int vertex = 0; vertex \u003c n; vertex++) {\n            if(visited[vertex] == -1) {\n                boolean isBipartite = isBipartite(graph, vertex, visited);\n                if(!isBipartite)\n                    return false;\n            }\n        }\n        return true;\n    }\n    \n    private boolean isBipartite(Map\u003cInteger,List\u003cInteger\u003e\u003e graph, int vertex, int[] visited) {\n        Queue\u003cint[]\u003e q = new ArrayDeque\u003c\u003e();\n        q.add(new int[]{vertex, 0});\n        \n        while(!q.isEmpty()) {\n            int[] node = q.remove();\n            int v = node[0];\n            if(visited[v] != -1) {\n                if(visited[v] != node[1])\n                    return false;\n            } else {\n                visited[v] = node[1];\n            }\n            \n            if(graph.get(v) != null) {\n                for(int neighbor : graph.get(v)) {\n                    if(visited[neighbor] == -1) {\n                        q.add(new int[]{neighbor, node[1] + 1});\n                    }\n               }   \n            }\n        }\n        return true;\n    }\n}\n```\n\n# References :\nhttps://github.com/eMahtab/is-graph-bipartite\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fpossible-bipartition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fpossible-bipartition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fpossible-bipartition/lists"}