SGU 323 Aviamachinations
Aviamachinations
This problem will be judged on SGU. Original ID: 323
64-bit integer IO format: %I64d Java class name: Solution
The Antimonopoly Committee was disbanded as a result of a government crisis. So, Don Berlione decided to close all but one airline. Naturally, this company should have flights (possibly including stopovers) from any town of Berland to any other one. To be able to choose the airline satisfying the above requirement, Don Berlione decided to carry out a number of fake purchase-sell operations. During a purchase-sell operation a flight of one airline is passed under the control of another airline. A purchase-sell operation is just a money transfer from one pocket to another. But still a special tax should be paid to the government for each operation.
So each flight is characterized by two towns it connects, the airline it belongs to and the tax amount that should be paid for a purchase-sell operation.
Your task is to find P — the minimum possible amount of money Don Berlione needs to spend to make it possible to leave only one airline carrying out flights (possibly with stopovers) from each town of Berland to any other. Also you need to suggest a plan of actions for Don Berlione.
Input
Output
Sample Input
sample input |
sample output |
4 3 4 |
5 2 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
class ARC {
public:
int u,v;
ARC(int x = ,int y = ) {
u = x;
v = y;
}
};
class ARC1:public ARC {
public:
int w,id;
ARC1(int x = ,int y = ,int cw = ,int cid = ):ARC(x,y) {
w = cw;
id = cid;
}
bool operator<(const ARC1 &t) {
return w < t.w;
}
} g[maxn];
class ARC2:public ARC {
public:
int next;
ARC2(int x = ,int y = ,int nxt = -):ARC(x,y) {
next = nxt;
}
} e[maxn];
int head[maxn],uf[maxn],tot,n,m,k;
void init() {
for(int i = ; i <= n; ++i) uf[i] = i;
}
int Find(int x) {
return uf[x] = x == uf[x]?x:Find(uf[x]);
}
void add(int u,int v,int x) {
e[tot] = ARC2(u,v,head[x]);
head[x] = tot++;
}
vector<int>MST,ans,tans;
void Kruskal() {
init();
MST.clear();
sort(g,g+k);
for(int i = ; i < k; ++i) {
int x = Find(g[i].u),y = Find(g[i].v);
if(x == y) continue;
uf[x] = y;
MST.push_back(i);
if(MST.size() >= n-) return;
}
}
void solve() {
int sum = 0x3f3f3f3f,id,tsum;
for(int i = ; i <= m; ++i) {
init();
tans.clear();
for(int j = head[i]; ~j; j = e[j].next) {
int x = Find(e[j].u),y = Find(e[j].v);
if(x != y) uf[x] = y;
}
for(int j = tsum = ; j < MST.size(); ++j) {
int x = Find(g[MST[j]].u),y = Find(g[MST[j]].v);
if(x == y) continue;
tsum += g[MST[j]].w;
uf[x] = y;
tans.push_back(MST[j]);
}
if(tsum < sum) {
sum = tsum;
id = i;
ans.clear();
std::copy(tans.begin(),tans.end(),std::back_inserter(ans));
}
}
printf("%d %d %d\n",sum,id,ans.size());
bool flag = false;
sort(ans.begin(),ans.end());
for(int i = ; i < ans.size(); ++i) {
if(flag) putchar(' ');
printf("%d",g[ans[i]].id);
flag = true;
}
putchar('\n');
}
int main() {
int a,b,c,p;
scanf("%d %d %d",&n,&m,&k);
memset(head,-,sizeof(head));
for(int i = tot = ; i < k; ++i) {
scanf("%d %d %d %d",&a,&b,&c,&p);
g[i] = ARC1(a,b,p,i + );
add(a,b,c);
}
Kruskal();
solve();
return ;
}
SGU 323 Aviamachinations的更多相关文章
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 树形DP求树的重心 --SGU 134
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...
- SGU 170 Particles(规律题)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个 ...
- SGU 179 Brackets light(生成字典序的下一个序列)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=179 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' ...
随机推荐
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
- JConsole远程监控Tomcat7
下面技术应用于最优质的水果的鲜果篮 一.设置服务端: 1.增加Listener到conf/server.xml <Listener className="org.apache.cata ...
- BZOJ4259: 残缺的字符串 & BZOJ4503: 两个串
[传送门:BZOJ4259&BZOJ4503] 简要题意: 给出两个字符串,第一个串长度为m,第二个串长度为n,字符串中如果有*字符,则代表当前位置可以匹配任何字符 求出第一个字符串在第二个字 ...
- thinkPHP的模板是做什么用的
thinkPHP的模板是做什么用的 问题 为什么PHP中ThinkPHP有做类似模板引擎的东西?smarty也是?这些到底有何用? 我是真没发现它们的用处在哪里?分离了前端和PHP的依赖?HTML文件 ...
- ListView有Header时的position情况
问题: headerView 为第0个view,item 的 pos会从1开始. 解决方式: position减去 listView.getHeaderViewsCount().例如我想得到list ...
- PostgreSQL Replication之第四章 设置异步复制(8)
4.8 处理时间线 时间线是一个您必须要知道的一个重要的概念,尤其是当您规划一个大型的设置的时候. 那么,什么是时间线呢?事实上,它是XLOG的一个分支.正常情况下,刚设置的一个数据库实例使用的时间线 ...
- Generic type test java
package test; public class GenericTest { public class Room<T> { private T t; public void add(T ...
- iOS开发——根据数组中的字典中的某一元素排序
数组中的元素是字典,字典中的某一个元素,比如说姓名,现在需要按照姓名的首字母来排序,怎么搞? 做法很简单,在字典中加一个元素,保存姓名的首字母,然后用下面的方法排序. - (void)sortWifi ...
- 【转载】解决django models文件修改后的数据库同步问题——south模块
转载链接:https://www.cnblogs.com/frchen/p/5732490.html 在使用django进行开发时,往往需要根据不同的需求对model进行更改.而这时候,python ...
- 20180929 北京大学 人工智能实践:Tensorflow笔记06
入戏 需要修改成如下: (完)