亚麻 oa2 算法 无向图

2256
4
求问一道无向图的题,蠡口的帖子失效,网上找不到答案,所有在此就答案,最好可以是java的答案,亚麻的2020 的oa,十分感谢。新人,添加链接需要审核,所以直接上伪链接 aonecode.com/amazon-online-assessment-shopping-patterns

题目大概是在无向图中找到所有顶点数为3的环,并计算出这些环的外联顶点数量,求最小的外联顶点数:
Amazon is trying to understand customer shopping patterns and offer items that are regularly bought together to new customers. Each item that has been bought together can be represented as an undirected graph where edges join often bundled products. A group of n products is uniquely numbered from 1 of product_nodes. A trio is defined as a group of three related products that all connected by an edge. Trios are scored by counting the number of related products outside of the trio, this is referred as a product sum.

Given product relation data, determine the minimum product sum for all trios of related products in the group. If no such trio exists, return -1.

十分感谢帮助!
  • 3
4条回复