We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Tripartite Matching

# Tripartite Matching

+ 0 comments https://zeroplusfour.com/tripartite-matching-hackerrank-solution/

Here's how I did in all languages Java 8 , C++ , C , Python 3, Python 2.

+ 0 comments import sys def main(): N = int(sys.stdin.readline()) M = [] G = [] for i in range(3): M.append(int(sys.stdin.readline())) G.append([set() for _ in range(N)]) for _ in range(M[i]): u, v = map(int, sys.stdin.readline().split()) u, v = u - 1, v - 1 G[i][u].add(v) G[i][v].add(u) cpt = 0 for a in range(N): for b in G[0][a]: for c in G[1][b]: if a in G[2][c]: #print a,b,c cpt += 1 print(cpt) main()

+ 0 comments Its impossible to complete in c# without modfying the process of reading data from console (one must modify Main method)

+ 0 comments In the task description it is written that:

- the graphs are unweighted and undirected
- "Each graph contains
**no cycles**and any pair of directly connected nodes is connected by a maximum of edge."

**But**in the sample input the second graph is the following:3 1 2 1 3 2 3

Which

**contains a cycle**. What am I misunderstanding? I would really appriciate some help.

+ 0 comments Are there not 6 possible triples on the sample input?

Load more conversations

Sort 11 Discussions, By:

Please Login in order to post a comment