#B3712. Party Handshakes

    ID: 11371 Type: Default 1000ms 256MiB

Party Handshakes

Party Handshakes

There are \( n \) people at a party (including Fusu). However, not every pair of people know each other, and even if they do, their relationship is not necessarily friendly.

For any two persons \( u \) and \( v \), their mutual relationship can be one of the following three types:

  1. Enemies
  2. Friends
  3. Strangers

The party includes an activity where people shake hands with each other. The handshake between any two persons \( u \) and \( v \) follows these rules:

  1. If \( u \) and \( v \) are friends, they must shake hands.
  2. If \( u \) and \( v \) are enemies, they do not shake hands.
  3. If \( u \) and \( v \) are strangers, then if there exists a person \( w \) such that \( w \) is a friend of one and an enemy of the other, \( u \) and \( v \) do not shake hands; otherwise, they must shake hands.

Simplifying the third rule: Between a pair of strangers, if one of them has a friend who is also the enemy of the other, then they do not shake hands; otherwise, they do.

You are given that there are \( p \) pairs of friends and \( q \) pairs of enemies. All remaining pairs are classified as strangers. Your task is to calculate how many handshakes occur in total at the party.

Input Format: The first line contains three integers \( n, p, q \). The following \( p \) lines each contain two integers representing a pair of friends. The next \( q \) lines each contain two integers representing a pair of enemies. It is guaranteed that except for these \( p+q \) pairs, every other pair of people are strangers.

inputFormat

The input consists of multiple lines:

  • The first line contains three space-separated integers: \( n \) (the total number of people), \( p \) (the number of friend pairs), and \( q \) (the number of enemy pairs).
  • The next \( p \) lines each contain two integers \( u \) and \( v \), denoting that person \( u \) and person \( v \) are friends.
  • The following \( q \) lines each contain two integers \( u \) and \( v \), denoting that person \( u \) and person \( v \) are enemies.

outputFormat

Output a single integer indicating the total number of handshakes that occur at the party.

sample

3 1 1
1 2
2 3
1