問題一覧 > 通常問題

No.1293 Two Types of Roads

レベル : / AI推定難易度 : 1125 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 141
作問者 : 沙耶花 / テスター : tatyam
お気に入りにしたユーザー ProblemId : 3941 / 自分の提出
問題文最終更新日: 2020-09-29 23:33:30
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 275 (順位表) の他の問題:

Problem Statement

The country where Sayaka lives has $N$ cities.
There are also $D$ motorways and $W$ pedestrian roads connecting cities.
The $i$-th motorway allows travel in both directions between cities $a_i$ and $b_i$.
Similarly, the $i$-th pedestrian road allows travel in both directions between cities $c_i$ and $d_i$.

Find the number of pairs of integers $(u,v)\,(1 \le u,v \le N,u \ne v)$ satisfying the following condition.

  • It is possible to move from city $u$ to city $v$ by traversing 0 or more motorways and then 0 or more pedestrian roads, in this order.

Input

$N \ D \ W$
$a_1\  b_1$
$\vdots$
$a_{D}\  b_{D}$
$c_1\  d_1$
$\vdots$
$c_{W} \ d_{W}$

  • $2 \le N \le 10^5$
  • $1 \le D,W \le \min\left(10^5,\frac{N(N-1)}{2}\right)$
  • $1 \le a_i < b_i \le N$
  • If $i \ne j$, then $(a_i,b_i) \ne (a_j,b_j)$
  • $1 \le c_i < d_i \le N$
  • If $i \ne j$, then $(c_i,d_i) \ne (c_j,d_j)$
  • All inputs are integers

Output

Output the answer.
Print a newline at the end.

Sample

Sample 1
Input
4 2 1
1 2
2 3
2 4
Output
10

The pairs $(u,v)=(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,2)$ satisfy the condition.

Sample 2
Input
10 5 5
1 2
1 3
1 4
2 4
3 7
3 8
2 4
1 3
9 10
1 10
Output
47

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。