← 返回 linkedin 的题目列表Degree of Connection Between LinkedIn Users
类型:online_judge
Given two LinkedIn users, calculate the degree of connection between them. Assume there is a social network graph where nodes are users and edges are connections between users. Your task is to start from one user, use a Breadth-First Search (BFS), find the target user, and calculate the degree of connection between them.
Input
ID of the starting user node
ID of the target user node
List of user connections, in the form of pairs of user IDs
Output
An integer representing the minimum degree of connection between the starting user and the target user.
Constraints
The network contains up to 10,000 users and 50,000 connections
Example
Input:
Starting user ID: 1
Target user ID: 4
Connections: [(1, 2), (2, 3), (3, 4)]
Output: 3
Example
Input
1
4
3
1 2
2 3
3 4