#P9008. Party Handshakes
Party Handshakes
Party Handshakes
There are \(n\) people at the party (including Fusu). However, not every two persons know each other, and even if two persons are acquainted, their relationship might not be good.
For every pair of distinct persons \(u\) and \(v\), their relationship is one of the following:
- Enemies
- Friends
- Strangers
The main activity at the party is handshaking. The handshake between any two persons \(u\) and \(v\) is governed by the rules below:
- If \(u\) and \(v\) are friends, then they must shake hands once.
- If \(u\) and \(v\) are enemies, then they do not shake hands.
- If \(u\) and \(v\) are strangers, and there exists a person \(w\) such that \(w\) is a friend of one and an enemy of the other, then \(u\) and \(v\) do not shake hands; otherwise, they must shake hands once.
Simplifying rule 3: For a pair of strangers, if one of them has a friend who is also an enemy of the other, then they will not shake hands; otherwise, they will.
You are given \(p\) pairs of friends and \(q\) pairs of enemies. All other pairs are strangers. Calculate the total number of handshakes at the party.
Note that all relationships are mutual. Also, each handshake between a pair is counted exactly once.
inputFormat
The first line contains three integers \(n\), \(p\), and \(q\) -- the number of people, the number of friend pairs, and the number of enemy pairs respectively.
The following \(p\) lines each contain two integers \(u\) and \(v\) indicating that persons \(u\) and \(v\) are friends.
The next \(q\) lines each contain two integers \(u\) and \(v\) indicating that persons \(u\) and \(v\) are enemies.
It is guaranteed that each pair of persons appears at most once in the friend/enemy lists and that friend/enemy relationships are symmetric.
outputFormat
Output a single integer -- the total number of handshakes at the party.
sample
3 1 1
1 2
2 3
1