#699
Unrated
DFS Order
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has a simple undirected graph with vertices labeled 1N1\dots N (2N7502\le N\le 750). She generates a depth-first search (DFS) order of the graph by calling the function dfs(1)\texttt{dfs}(1), defined by the following C++ code. Each adjacency list (adj[i]\texttt{adj}[i] for all 1iN1\le i\le N) may be permuted arbitrarily before starting the depth first search, so a graph can have multiple possible DFS orders.

vector vis(N + 1); vector<vector> adj(N + 1); // adjacency list vector dfs_order;

void dfs(int x) { if (vis[x]) return; vis[x] = true; dfs_order.push_back(x); for (int y : adj[x]) dfs(y); }

You are given the initial state of the graph as well as the cost to change the state of each edge. Specifically, for every pair of vertices (i,j)(i,j) satisfying 1i<jN1\le i<j\le N, you are given an integer ai,ja_{i,j} (0<ai,j10000<|a_{i,j}|\le 1000) such that

If ai,j>0a_{i,j}>0, edge (i,j)(i,j) is not currently in the graph, and can be added for cost ai,ja_{i,j}.If ai,j<0a_{i,j}<0, edge (i,j)(i,j) is currently in the graph, and can be removed for cost ai,j-a_{i,j}.

Determine the minimum total cost to change the graph so that [1,2,N][1,2\dots,N] is a possible DFS ordering.

입력

The first line contains NN.

Then N1N-1 lines follow. The j1j-1th line contains a1,j,a2,j,,aj1,ja_{1,j}, a_{2,j}, \dots, a_{j-1,j} separated by spaces.

출력

The minimum cost to change the graph so that [1,2,,N][1,2,\dots, N] is a possible DFS ordering.

예제 입력 1

4
1
2 3
40 6 11

예제 출력 1

10

예제 입력 2

5
-1
10 -2
10 -7 10
-6 -4 -5 10

예제 출력 2

5

예제 입력 3

4
-1
-2 300
4 -5 6

예제 출력 3

9

점수

Inputs 4-9: All ai,j>0a_{i,j}>0Inputs 10-16: N50N\le 50Inputs 17-23: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.