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 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' ...
随机推荐
- html-上左右布局方式---ShinePans
文件包括 main.html top.html left.html childhood.html moonsong.html herethesea.html 主要布局效果: 代码: main ...
- light oj 1317
Description You probably have played the game "Throwing Balls into the Basket". It is a si ...
- NUTCH2.3 hadoop2.7.1 hbase1.0.1.1 solr5.2.1部署(一)
Precondition: hadoop 2.7.1 Nutch 2.3 hbase 1.0.1.1 / hbase 0.98.13 solr 4.8.1 Linux version 3.16. ...
- 转发真阿当老师的一片文章 受益匪浅 (出处:http://cly84920.blog.163.com/blog/static/24750013320158203575958/)
忽悠程序员做一辈子程序员,以白胡子白头发hacker为目标的人有两种: 1,自己不写程序,但需要有将才为自己打下手的人,这种人往往看他资质和勤奋均平平,却成了你领导.别不服,这种人虽不见得有帅才的能力 ...
- 查看suse系统版本
cat /etc/*-release OR lsb_release -d
- 福建省赛--Problem E The Longest Straight(标记+二分)
Problem E The Longest Straight Accept: 71 Submit: 293 Time Limit: 1000 mSec Memory Limit : 327 ...
- 解读邮箱正则表达式:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
转自:http://www.cnblogs.com/joyceTING/archive/2013/05/09/3069089.html正则表达式 \w+([-+.]\w+)*@\w+([-.]\w+) ...
- vue -- 7 个 有用的 Vue 开发技巧
1 状态共享 随着组件的细化,就会遇到多组件状态共享的情况, Vuex当然可以解决这类问题,不过就像 Vuex官方文档所说的,如果应用不够大,为避免代码繁琐冗余,最好不要使用它,今天我们介绍的是 vu ...
- kali 2.0 linux中的Nmap的操作系统扫描功能
不多说,直接上干货! 可以使用-O选项,让Nmap对目标的操作系统进行识别. msf > nmap -O 202.193.58.13 [*] exec: nmap -O 202.193.58.1 ...
- Storm框架基础(一)
* Storm框架基础(一) Storm简述 如果你了解过SparkStreaming,那么Storm就可以类比着入门,在此我们可以先做一个简单的比较: 在SparkStreaming中: 我们曾尝 ...