Spies Like Us
InterviewTime limit2sMemory limit512 MB
Given a bipartite graph, decide whether any two vertices on the same side share at most one common neighbor on the other side.
- Level
Medium5 of 10
- Topics
- Graph, Hash map, Implementation, Brute force
- Solved
- No attempts yet
Problem
An ultra-secret spy organization is worried about a hidden conspiracy. To avoid groupthink, the organization splits its agents into two teams, and each team runs its own investigation.
Occasionally, members of different teams must interact through pre-designated contact points: pairs of agents on opposite teams who are permitted to talk to each other under special circumstances. To keep communication between the teams limited, the organization enforces one rule.
Any two agents on the same team may have at most one common contact on the other team.
You are given the planned set of contact points between the two teams. Determine whether the plan satisfies this rule.
Input
The first line contains two space-separated integers and (), the number of agents on the first and second teams, respectively.
The second line contains an integer (), the number of contact points.
Each of the next lines contains two integers and (, ), meaning that agent of the first team and agent of the second team are allowed to communicate.
Output
Output a single line containing YES if the plan satisfies the rule that any two agents on the same team have at most one common contact on the other team, and NO otherwise.