CF1082G.Petya and Graph
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.
The weight of the i-th vertex is ai.
The weight of the i-th edge is wi.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. The set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
The weight of a subgraph is the sum of the weights of its edges, minus the sum of the weights of its vertices. You need to find the maximum weight of subgraph of given graph. The given graph does not contain loops and multiple edges.
佩蒂亚有一个简单图(即不含自环和重边的图),该图包含 n 个顶点和 m 条边。
第 i 个顶点的权值为 ai。
第 i 条边的权值为 wi。
图的一个子图是指图中某些顶点的集合以及某些边的集合,且需满足如下条件:该边集合中的每条边的两个端点都必须属于所选的顶点集合。
子图的权值定义为:其所有边的权值之和减去其所有顶点的权值之和。你需要求出给定图的所有子图中权值的最大值。给定图不含自环和重边。
输入格式
The first line contains two numbers n and m (1≤n≤103,0≤m≤103) - the number of vertices and edges in the graph, respectively.
The next line contains n integers a1,a2,…,an (1≤ai≤109) - the weights of the vertices of the graph.
The following m lines contain edges: the i-e edge is defined by a triple of integers vi,ui,wi (1≤vi,ui≤n,1≤wi≤109,vi=ui). This triple means that between the vertices vi and ui there is an edge of weight wi. It is guaranteed that the graph does not contain loops and multiple edges.
第一行包含两个整数 n 和 m(1≤n≤103, 0≤m≤103),分别表示图中的顶点数和边数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示图中各顶点的权值。
接下来的 m 行描述边:第 i 条边由三个整数 vi,ui,wi(1≤vi,ui≤n, 1≤wi≤109, vi=ui)定义。该三元组表示顶点 vi 与 ui 之间存在一条权值为 wi 的边。保证图中不含自环和重边。
输出格式
Print one integer — the maximum weight of the subgraph of the given graph.
输出一个整数——给定图的子图的最大权重。
输入输出样例
输入#1
4 5 1 5 2 2 1 3 4 1 4 4 3 4 5 3 2 2 4 2 2
输出#1
8
输入#2
3 3 9 7 8 1 2 1 2 3 2 1 3 3
输出#2
0
说明/提示
In the first test example, the optimal subgraph consists of the vertices 1,3,4 and has weight 4+4+5−(1+2+2)=8. In the second test case, the optimal subgraph is empty.
在第一个测试样例中,最优子图包含顶点 {1,3,4},其权重为 4+4+5−(1+2+2)=8。在第二个测试用例中,最优子图为空。
输入解题思路,AI测评打分。不知道怎么写?