← 返回 stripe 的题目列表Six Degrees of Collusion - Fraud Ring Size
类型:online_judge
Problem: Fraud Ring Size
Direct device sharing is not enough to detect sophisticated fraud rings. Each log now contains a user, a device, and a credit-card hash:
user_id,device_id,credit_card
Two users are connected if they share either the same device_id or the same credit_card. Connectivity is transitive: if A shares a device with B, and B shares a card with C, then A, B, and C are in the same Fraud Ring.
Given target_user, return the number of unique users in the Fraud Ring containing the target user, including the target user. If the target never appears, return 0.
Input Format
n
transaction_1
transaction_2
...
transaction_n
target_user
Output Format
Print one integer: the number of unique users in the connected component containing the target user.
Constraints
0 <= n <= 2 * 10^5
All fields are non-empty strings without commas
A user may appear multiple times with different devices or cards
Connections may be chained through identifiers of arbitrary length
Example
Input
5
Alice,D1,CC1
Bob,D1,CC2
Charlie,D2,CC2
David,D3,CC3
Eve,D3,CC4
Alice
Output
3