题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4762
Time limit: 3000 ms

Problem Description

You are in charge of preparing the conference hall for the closing ceremony of ACM ICPC. You had hired a perfectionist sentimental room designer to design an elegant decoration for the old hall. The ceremony is going to start in a few hours and the designer has just informed you of the completion of the decoration. When you reach the conference hall, you confront a strange circuit on the wall. The designer starts explaining the meanings of life and ACM ICPC hidden under each piece of the circuit. The circuit consists of LEDs (Light Emitting Diodes) interconnected with junctions and wires. You ask whether the LEDs should be switched on. “Of course!” the designer responds, “Each and every LED must be lit, otherwise the whole work is junk!” You look around the circuit to find its power plug.

  • Where is the power plug?

  • Huh? It’s beyond the scope of my work! It is you who has to provide the electricity to the LEDs. And be careful! Do not remove or modify a single part of the circuit; Just connect power supply cables to the junctions. I have to leave right now. I will send a report of my perfect work to your manager. Bye.

Left alone with the bizarre circuit, you start inspecting the circuit.

Unlike incandescent light bulbs, which emit light regardless of the electrical polarity, LEDs only emit light with the correct electrical polarity (i.e. when their anode pin has a higher electric potential than the cathode pin). Each LED has a minimum voltage. An LED does not emit (even with the correct polarity) if the electrical potential difference of its pins is less than its minimum voltage. Each LED has also a maximum voltage. An LED is destroyed if its electrical potential difference exceeds its maximum voltage.

Your inspection on the circuit shows it consists of three types of components:

  • LEDs: Fortunately, all LEDs of the circuit are of the same type, and so having the same minimum voltage, and the same maximum voltage.
  • Junctions: Each of the two pins of an LED in the circuit is connected to a junction. Junctions are not only a place for connecting the LED pins, but also for connecting the wire end-points.
  • Wires: Each wire has two end-points and connects a junction directly to another junction forcing them to have the same electric potential.

By connecting external electrical poles (with different values of voltage) to each of the junctions of the circuit, you can inject different electric potentials to the junctions. Note that each junction must be connected to an external electrical pole. Be careful of short circuits: the end-points of each wire MUST have the same electric potential. By convention, we can assume the minimum electric potential to be zero. So, all the electric potentials can be considered to be nonnegative.

Now, you have to buy an external power supply that provides you with the required electrical poles. The cost of such power supplies depends on their upper-bound: the maximum voltage they provide.

Given the specification of the LED circuit, you have to write a program that tests if it is possible to light all the LEDs correctly (with no short circuits, and no LED destruction). In the case of the possibility, the program should also compute the minimum possible upper-bound of power supply with which all LEDs can emit light.

Input

The input consists of several test cases. Each test case describes an LED circuit and starts with a line containing 5 space-separated integers JJJ, LLL, WWW, mmm, and MMM, where JJJ is the number of junctions (2≤J≤500)(2 ≤ J ≤ 500)(2≤J≤500), LLL is the number of LEDs (1≤L≤5,000)(1 ≤ L ≤ 5, 000)(1≤L≤5,000), WWW is the number of wires (0≤W≤5,000)(0 ≤ W ≤ 5, 000)(0≤W≤5,000), and mmm and MMM are the minimum and maximum voltage of LEDs respectively (1≤m<M≤1000)(1 ≤ m < M ≤ 1000)(1≤m<M≤1000). Assume that the junctions are numbered 111 through JJJ.

Each of the next LLL lines represents an LED with two space-separated integers. The first integer is the number of the junction to which the anode pin of the LED is connected and the second integer is the number of the junction for the cathode pin. Then, WWW lines follow, each describing a wire of the circuit using two space-separated integers: the junctions the wire directly connects.

The input terminates with a line containing ‘00000’‘0 0 0 0 0’‘00000’ (omit the quotes).

Output

Write a single line of output for each test case. If there is no way to correctly light all the LEDs in the circuit of that test case, only write the word ‘Impossible’‘Impossible’‘Impossible’ (with no quotes). Otherwise, write a single integer: the minimum upperbound of power supply with which all the LEDs can be lit.

Sample Input

2 1 0 3 5
1 2
3 2 0 3 5
1 2
3 2
3 2 0 3 5
3 2
1 3
3 1 1 3 5
1 2
2 3
3 1 2 3 5
1 2
2 3
3 1
3 3 0 3 5
1 2
2 3
1 3
3 3 0 3 6
1 2
2 3
1 3
4 2 2 2 7
1 2
3 4
3 1
2 4
4 2 2 2 7
1 2
3 4
3 2
1 4
0 0 0 0 0

Sample Output

3
3
6
3
Impossible
Impossible
6
2
Impossible

Problem solving report:

Description:给出结点的数量、LED的数量以及结点的连接状态、导线数以及结点的连接状态、LED的最小和最大电压,求使其所有LED灯点亮的最小电压。
Problem solving:利用最短路的方法求,每个LED之间的电压正向为m,反向设为-M,而导线两端设为0,故我们只需要虚构一个结点0,求出0到其余结点的所有电压,其中最大和最小的差值即为满足条件的最小电压值。

Accepted Code:

/* * @Author: lzyws739307453 * @Language: C++ */
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
const int MAXM = 1e4 + 5;
const int inf = 0x3f3f3f3f;
struct edge {int to, da, ne;edge() {}edge(int to, int da, int ne) : to(to), da(da), ne(ne) {}
}e[MAXM << 1];
int n, cnt;
bool vis[MAXN];
int dis[MAXN], inq[MAXN], he[MAXN];
void Add(int u, int v, int w) {e[++cnt] = edge(v, w, he[u]);he[u] = cnt;
}
bool Spfa() {queue <int> Q;for (int i = 1; i <= n; i++) {Q.push(i);inq[i] = 0;dis[i] = 0;vis[i] = true;}while (!Q.empty()) {int u = Q.front();Q.pop();vis[u] = false;for (int i = he[u]; ~i; i = e[i].ne) {int v = e[i].to;if (dis[v] < dis[u] + e[i].da) {dis[v] = dis[u] + e[i].da;if (++inq[v] >= n)return true;if (!vis[v]) {Q.push(v);vis[v] = true;}}}}return false;
}
int main() {int u, v, l, w, m, M;while (scanf("%d%d%d%d%d", &n, &l, &w, &m, &M), n) {cnt = 0;memset(he, -1, sizeof(he));for (int i = 0; i < l; i++) {scanf("%d%d", &u, &v);Add(u, v, m);Add(v, u, -M);}for (int i = 0; i < w; i++) {scanf("%d%d", &u, &v);Add(u, v, 0);Add(v, u, 0);}if (Spfa()) {printf("Impossible\n");continue;}int min_ = inf, max_ = -inf;for (int i = 1; i <= n; i++) {min_ = min(min_, dis[i]);max_ = max(max_, dis[i]);}printf("%d\n", max_ - min_);}return 0;
}

UVALive - LED Circuit(Spfa)相关推荐

  1. 西北工业大学计算机毕业论文,光纤通信发射机本科毕业论文 西北工业大学.docx...

    光纤通信发射机本科毕业论文 西北工业大学 本科毕业设计论文 PAGE 41 摘 要 直接调制光发射机能完成对电信号的处理,其功能是把电脉冲信号变成光脉冲信号.本文先介绍了光纤通信的发展背景,光纤相对于 ...

  2. UVALive 4223 Trucking 二分+spfa

    Trucking 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...

  3. 可否使用串联LED(或者光敏LED)来制作光电检测板?

    简 介: 在通常情况下,使用LED都是利用它的将电能转换成光的功能.它虽然有光敏特性,但比起光电池.光敏三极管效率低.但LED作为批量的器件,它的价格低廉.所以如果能够开发它作为光电传感器则会在很多应 ...

  4. raspberry pi_使用Raspberry Pi和GPIO引脚控制外部LED

    raspberry pi by Shahbaz Ahmed Shahbaz艾哈迈德(Shahbaz Ahmed) 使用Raspberry Pi和GPIO引脚控制外部LED (Controlling a ...

  5. HDU ACM 1224 Free DIY Tour (SPFA)

    Free DIY Tour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. 微型计算机系统与接口流水灯,单片机的LED流水灯系统设计2.doc

    单片机的LED流水灯系统设计2 学号:0809111030 2010 - 2011学年 第2学期 <单片机应用技术> 课 程 设 计 报 告 题 目: 单片机的LED流水灯系统设计 专 业 ...

  7. STEAM上的一款电路模拟神器 — CRUMB Circuit Simulator

    摘要:这几天在逛steam商店时,发现了一款有意思的电路仿真软件CRUMB Circuit Simulator(CRUMB电路模拟器),觉得挺有意思的,就下载了玩了一下. 这款模拟电路软件的东西不多, ...

  8. 【单片机应用】项目一 发光二极管LED控制

    发光二极管LED控制 一.LED介绍 二.LED的工作原理 三.小项目:点亮一个LED 点亮一个发光二极管 认识PROTEUS 用PROTEUS设计第一个LED控制电路 工作过程 LED点亮程序 点亮 ...

  9. .playground文件_部署可教学机器:Circuit Playground Express,Arduino,P5.js,TinyUSB

    .playground文件 什么是可教学机? (What is Teachable Machine?) Teachable Machine is a web-based tool that makes ...

最新文章

  1. 机器学习中的数学意义
  2. FPGA/IC技术交流2020
  3. Android的圆角按钮和按钮颜色
  4. 大于小于优化_工程优化设计与Matlab实现——优化设计的数学基础
  5. 南方s730手簿说明书_最新S730手簿及3.0简易操作82
  6. mule esb 集成_集成框架比较– Spring集成,Mule ESB或Apache Camel
  7. 语雀携手Teambition,玩转项目协作与知识管理
  8. Python《必应bing桌面图片爬取》
  9. nginx配置跨域、gzip加速、代理详细讲解
  10. Windows Server 2016如何配置定期执行任务计划
  11. [二分搜索|快速选择] leetcode 4 寻找两个正序数组的中位数
  12. 某虚拟化项目中思科与华为交换机链路聚合互连案例
  13. ReentrantLock深入学习
  14. oracle练习(mldn视频)二
  15. js将阿拉伯数字转换成汉字大写
  16. 蓝桥杯 java 楼梯,递归1之楼梯问题
  17. 认真学习设计模式之适配器模式(Adapter Pattern)/包装器模式
  18. 用友 uap NC系统单点登录总结
  19. 【目标检测】《DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection》论文阅读笔记
  20. B450M MORTAR    AMD R5 3600   组装机

热门文章

  1. Apipost私有化部署活动即将火热开启,企业无忧
  2. 中学生人际交往5大技巧
  3. 用Python制作一个数据预处理小工具,多种操作,一键完成,非常实用!
  4. 封神台靶场(一)为了女神小芳 【SQL注入攻击】(超级详细)
  5. SRV记录生成的完整教程
  6. 网易邮箱批量登泉器v1.0
  7. 饿了不能吃的11种食品
  8. 【实施】项目实施工程中的确认事项
  9. 3D点云初探:基于全卷积神经网络实现3D物体识别
  10. 深度科普:拆解让机器人走路更「丝滑」的TEB算法