Frequency Hopping

Time Limit: 10000ms
Memory Limit: 131072KB

This problem will be judged on UVA. Original ID: 11248
64-bit integer IO format: %lld      Java class name: Main

20th July, 1942

Colonel Al Pacheno,According to the previous order “ref:    232/UK44i/334sda#nh$X3y”, you are required back in the DOI (Department of intelligence, London) to head the special programming contingent immediately. You are to assign a programmer for the job whose specification is attached with this letter. Level 3 Secrecy must be maintained. 

Sincerely,
General Shaan Konary
Director, DOI
London
Ps: Sorry to ruin your Caribbean holiday

232/UK44i/334sda#nh$X3y/Appx-301a
At this moment, through out Europe, our base station numbers 1 to N are actively operational
through wireless channels. Immediately we require sending C secret message fragments from
our head quarters (base station 1) to Nth base station. Germans have developed Zämmhäim – a
machine which jams the frequency channel between base stations after a station has sent a
message fragment. In that case, the base stations must transmit using a different frequency
channel for each message fragment. There are several unidirectional channels set up between
base stations at this moment. We can only make arrangements to set up number of frequency
channels only between two base stations. Your task is to check whether all the message
fragments can be sent to the desired base station with or without increasing frequency channel
between any two particular base stations. You have to give us all possible options if it is
required to increase frequency channel between two stations.
--End of Attachment

As members of Secret Programmers Group (SPG) you are assigned to solve this problem within 5 hrs
and deliver the solution directly to Colonel Al Pacheno. You have to maintain Level 3 secrecy and
destroy all documents corresponding to this as soon as you deliver the solution.

Input:
There will be multiple test cases. The first line of each test case contains three numbers N, E and C
where N (0<N<101) represents the number of base stations, E (E<10000) represents the number of
available connections between the base stations and C (C<2000000000) represents the number of
secret message fragments that are required to send from station 1 to station N. After that, there will be
E lines. Each line contains 3 numbers: b1(0<b1<101), b2(0<b2<101) and fp (0<fp<5001) which
represent the number of frequency channels available currently from b1 to b2. Input is terminated when
N=E=C=0. 1
Output:
For each test case, there will be one line of output. First, you have to print the case number. If it is
possible to send C secret message fragments from the current status the output will be “possible”.
Otherwise, you have to print all pairs of stations (in ascending order) if it is possible send the required
message fragments by increasing the frequency channel between any one of them. If it is still
impossible, you have to print “not possible”.

Sample Input Output for Sample Input
4 4 5
1 2 5
1 3 5
2 4 5
3 4 5
4 4 5
1 2 1
1 3 5
2 4 5
3 4 1
4 4 5
1 2 1
1 3 1
2 4 1
3 4 1
0 0 0

Case 1: possible
Case 2: possible option:(1,2),(3,4)
Case 3: not possible

Problemsetter: Syed Monowar Hossain
Special Thanks: Abdullah al Mahmud

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
};
arc e[maxn*];
int head[maxn],d[maxn],cur[maxn];
int tot,S,T,N,E,C,cnt;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs() {
memset(d,-,sizeof(d));
queue<int>q;
d[S] = ;
q.push(S);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow > && d[e[i].to] == -) {
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
pii rec[maxn*];
int dfs(int u,int low) {
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow > && d[e[i].to] == d[u]+&&(a=dfs(e[i].to,min(low,e[i].flow)))) {
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
rec[cnt++] = make_pair(i,a);
rec[cnt++] = make_pair(i^,-a);
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic() {
int ans = ;
cnt = ;
while(bfs()) {
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
void release(){
for(int i = ; i < cnt; ++i)
e[rec[i].first].flow += rec[i].second;
}
vector< pii >ans;
int main() {
int u,v,w,cs = ;
while(scanf("%d %d %d",&N,&E,&C),N||E||C) {
memset(head,-,sizeof(head));
S = ;
T = N;
for(int i = ; i < E; ++i) {
scanf("%d %d %d",&u,&v,&w);
add(u,v,w);
}
int flow = dinic();
printf("Case %d: ",cs++);
if(flow >= C) puts("possible");
else {
ans.clear();
for(int i = ; i < tot; i += ) {
if(e[i].flow == ){
e[i].flow = C;
if(flow + dinic() >= C) ans.push_back(make_pair(e[i^].to,e[i].to));
release();
e[i].flow = ;
}
}
if(ans.size()){
printf("possible option:");
sort(ans.begin(),ans.end());
for(int i = ,j = ans.size(); i < j; ++i)
printf("(%d,%d)%c",ans[i].first,ans[i].second,i+==j?'\n':',');
}else puts("not possible");
}
}
return ;
}

这样写 快很多啊

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
};
arc e[maxn*];
int head[maxn],d[maxn],cur[maxn];
int tot,S,T,N,E,C,cnt;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs() {
memset(d,-,sizeof(d));
queue<int>q;
d[T] = ;
q.push(T);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i^].flow > && d[e[i].to] == -) {
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[S] > -;
}
pii rec[maxn*];
int dfs(int u,int low) {aaa
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow > && d[u] == d[e[i].to]+&&(a=dfs(e[i].to,min(low,e[i].flow)))) {
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
rec[cnt++] = make_pair(i,a);
rec[cnt++] = make_pair(i^,-a);
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic() {
int ans = ;
cnt = ;
while(bfs()) {
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
void release(){
for(int i = ; i < cnt; ++i)
e[rec[i].first].flow += rec[i].second;
}
vector< pii >ans;
int main() {
int u,v,w,cs = ;
while(scanf("%d %d %d",&N,&E,&C),N||E||C) {
memset(head,-,sizeof(head));
S = ;
T = N;
for(int i = ; i < E; ++i) {
scanf("%d %d %d",&u,&v,&w);
add(u,v,w);
}
int flow = dinic();
printf("Case %d: ",cs++);
if(flow >= C) puts("possible");
else {
ans.clear();
for(int i = ; i < tot; i += ) {
if(e[i].flow == ){
e[i].flow = C;
if(flow + dinic() >= C) ans.push_back(make_pair(e[i^].to,e[i].to));
release();
e[i].flow = ;
}
}
if(ans.size()){
printf("possible option:");
sort(ans.begin(),ans.end());
for(int i = ,j = ans.size(); i < j; ++i)
printf("(%d,%d)%c",ans[i].first,ans[i].second,i+==j?'\n':',');
}else puts("not possible");
}
}
return ;
}

UVA 11248 Frequency Hopping的更多相关文章

  1. UVA 11248 - Frequency Hopping(网络流量)

    UVA 11248 - Frequency Hopping 题目链接 题意:给定一个网络,如今须要从1到N运输流量C,问是否可能,假设可能输出可能,假设不可能,再问能否通过扩大一条边的容量使得可能,假 ...

  2. uva 11248 Frequency Hopping (最大流)

    uva 11248 Frequency Hopping 题目大意:给定一个有向网络,每条边均有一个容量. 问是否存在一个从点1到点N.流量为C的流.假设不存在,能否够恰好改动一条弧的容量,使得存在这种 ...

  3. UVa 11248 Frequency Hopping (网络流)

    题意:给定上一个网络,每个边有一个容量,问你能不能从 1 到 n,使得流量为 c,如果不能,那么是不是可以修改一条边,使得达到. 析:背景就是一个网络流,如果原图能跑出来,那么就不用了,就肯定能达到, ...

  4. Uvaoj 11248 Frequency Hopping(Dinic求最小割)

    题意:1到n节点(节点之间有一定的容量),需要流过C的流量,问是否可以?如果可以输出possible, 否则如果可以扩大任意一条边的容量 可以达到目的,那么输出possible option:接着输出 ...

  5. Uva 11248 网络扩容

    题目链接:https://vjudge.net/contest/144904#problem/A 题意:给定一个有向网络,每条边均有一个容量.问是否存在一个从点1到点N,流量为C的流.如果不存在,是否 ...

  6. uva 10801 - Lift Hopping(最短路Dijkstra)

    /* 题目大意: 就是一幢大厦中有0-99的楼层, 然后有1-5个电梯!每个电梯有一定的上升或下降速度和楼层的停止的位置! 问从第0层楼到第k层最少经过多长时间到达! 思路:明显的Dijkstra , ...

  7. UVa 10801 - Lift Hopping(dijkstra最短路)

    根据题意,以每一层楼为顶点,每个电梯可以到达的两层楼之间的秒数为每一条边的权值,以此构建一个无向图.然后利用dijkstra求出最短的时间,注意每次换乘电梯需要等待60s(因为同一个电梯上的楼层是相互 ...

  8. UVa 821 Page Hopping【Floyd】

    题意:给出一个n个点的有向图,任意两个点之间都相互到达,求任意两点间最短距离的平均值 因为n很小,所以可以用floyd 建立出图,然后用floyd,统计d[][]不为0且不为INF的边的和及条数,就可 ...

  9. UVA 10801 Lift Hopping 电梯换乘(最短路,变形)

    题意: 有n<6部电梯,给出每部电梯可以停的一些特定的楼层,要求从0层到达第k层出来,每次换乘需要60秒,每部电梯经过每层所耗时不同,具体按 层数*电梯速度 来算.问经过多少秒到达k层(k可以为 ...

随机推荐

  1. JS中检测数据类型的多种方法

    面试当中经常会问到检测 js 的数据类型,我在工作当中也会用到这些方法.让我们一起走起!!! 首先给大家上一个案例 console.log(typeof "langshen"); ...

  2. 紫书 习题7-13 UVa 817(dfs+栈求表达式的值)

    题目链接  点击打开链接 这道题分为两个部分, 一用搜索枚举每种可能, 二计算表达式的值, 有挺多细节需要注意 特别注意我的代码中在计算表达式的值中用到了一个!(代码枚举中的!表示不加符号, 我现在说 ...

  3. COGS——T 1168. 机器调度

    http://www.cogs.pro/cogs/problem/problem.php?pid=1168 ★★   输入文件:machine.in   输出文件:machine.out   简单对比 ...

  4. Qt之窗体透明

    简述 关于窗体透明,经常遇到,下面我们针对常用的透明效果进行讲解: 全透明(主窗体.子窗体均透明) 主窗体透明(子窗体不透明) 子窗体透明(主窗体不透明) 简述 正常状态 全透明 效果 源码 主窗体透 ...

  5. 轻松学习JavaScript十七:JavaScript的BOM学习(二)

    JavaScript计时事件 通过使用JavaScript中的BOM对象中的window对象的两个方法就是setTimeout()方法和claerTimeout()方法,我们 有能力作到在一个设定的时 ...

  6. GitBlit中出现 error: remote unpack failed: error Missing tree

    clu@WASYGSHA01-1020 MINGW64 /d/ChuckLu/Git/Edenred/LISA_5.0.0.0 (local)$ git push origin preaction:p ...

  7. m_Orchestrate learning system---十八、mo项目的启示是什么

    m_Orchestrate learning system---十八.mo项目的启示是什么 一.总结 一句话总结:多看教程,体统看教程的学, 完全不懂的话百度的作用也不大 多学点,可以节约后面的超多时 ...

  8. Linux就该这么学 20181003(第四章Vim/shell/测试条件)

    参考链接https://www.linuxprobe.com/ vim文本编辑器 命令模式:控制光标移动,可对文本进行复制,黏贴,删除和查找工作 输入模式:正常的文本录入 末行模式:保存或退出文档,以 ...

  9. Android ViewPager系列之ViewPager一屏显示多个子页面

    ViewPager一屏显示多个子页面,常见的有两种形式: 1.当前展示的页面右侧显示一部分下个页面的内容 2.当前页面居中,左右两边分别显示上一个页面.下一个页面 第 1 种表现形式的实现代码 其实这 ...

  10. (转载) Android studio如何生成aar包

    Android studio如何生成aar包 标签: Android studio如何生成aaAndroid studio aarAndroid 如何生成aar包 2016-12-21 14:42 1 ...