Graph

5

1 votes
Tree, Dynamic Programming, Algorithms, Medium
Problem

Given two sequences  and . A graph is built with n vertices and n directed edges . Cost to change some  is   . Your goal is to make the graph strongly connected with minimum cost.

Input

The first line contains an integer n.

The second line contains n intergers, .

The third line contains n integers .

Output

An integer representing the answer.

Constraints

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Change  to 3 and  to 4.

Editor Image

?