bzoj 4602: [Sdoi2016]齿轮
4602: [Sdoi2016]齿轮
Description
Input
Output
Sample Input
3 3
1 2 3 5
2 3 5 -7
1 3 3 -7
3 3
1 2 3 5
2 3 5 -7
1 3 3 7
Sample Output
Case #2: No
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=;
const int M=;
#define eps 1e-8
int T,n,m,i,x,y,u,v,ok,Case,p[N];
int tot,head[N],Next[M<<],to[M<<];
double a[M<<],f[N];
void add(int u,int v,double x)
{
tot++;
to[tot]=v;
a[tot]=x;
Next[tot]=head[u];
head[u]=tot;
}
bool dfs(int x)
{
int i;
p[x]=;
for(i=head[x];i!=-;i=Next[i])
{
int y=to[i];
if(p[y]==)
{
f[y]=f[x]*a[i];
if(dfs(y)==) return ;
} else
if((f[x]*a[i]-f[y])>eps) return ;
}
return ;
}
int main()
{
scanf("%d",&T);
Case=;
while(T--)
{
scanf("%d%d",&n,&m);
tot=;
for(i=;i<=n;i++)
head[i]=-,p[i]=,f[i]=;
for(i=;i<=m;i++)
{
scanf("%d%d%d%d",&u,&v,&x,&y);
add(u,v,1.0*x/y);
add(v,u,1.0*y/x);
}
ok=;
for(i=;i<=n;i++)
if(p[i]==)
{
f[i]=1.0;
if(dfs(i)==)
{
ok=;
break;
}
}
Case++;
printf("Case #%d: ",Case);
if(ok==) printf("Yes\n");else printf("No\n");
}
return ;
}
bzoj 4602: [Sdoi2016]齿轮的更多相关文章
- BZOJ 4602: [Sdoi2016]齿轮 dfs
4602: [Sdoi2016]齿轮 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4602 Description 现有一个传动系统,包 ...
- [Sdoi2016]齿轮
4602: [Sdoi2016]齿轮 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 613 Solved: 324 [Submit][Status ...
- BZOJ4602 Sdoi2016 齿轮 【带权并查集】*
BZOJ4602 Sdoi2016 齿轮 Description 现有一个传动系统,包含了N个组合齿轮和M个链条.每一个链条连接了两个组合齿轮u和v,并提供了一个传动比x : y.即如果只考虑这两个组 ...
- bzoj4602 [Sdoi2016]齿轮
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4602 [题解] 对于每组齿轮(u, v)连边,权值为y/x(反向边x/y) 那么直接dfs计 ...
- BZOJ 4517: [Sdoi2016]排列计数
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 911 Solved: 566[Submit][Status ...
- 数学(错排):BZOJ 4517: [Sdoi2016]排列计数
4517: [Sdoi2016]排列计数 Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 693 Solved: 434[Submit][Status ...
- 动态规划(决策单调优化):BZOJ 4518 [Sdoi2016]征途
4518: [Sdoi2016]征途 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 532 Solved: 337[Submit][Status][ ...
- 图论(费用流):BZOJ 4514 [Sdoi2016]数字配对
4514: [Sdoi2016]数字配对 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 820 Solved: 345[Submit][Status ...
- 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表
4513: [Sdoi2016]储能表 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 395 Solved: 213[Submit][Status] ...
随机推荐
- linux===Ubuntu 上安装 Node.js
https://www.cnblogs.com/andfly/p/6681487.html
- nodejs 优雅的连接 mysql
1.mysql 及 promise-mysql nodejs 连接 mysql 有成熟的npm包 mysql ,如果需要promise,建议使用 promise-mysql: npm:https:// ...
- HDU 5116 Everlasting L
题目链接:HDU-5116 题意:给定若干个整数点,若一个点集满足P = {(x, y), (x + 1, y), . . . , (x + a, y), (x, y + 1), . . . , (x ...
- sleep() 函数
函数名: sleep 功 能: 执行挂起一段时间 用 法: unsigned sleep(unsigned seconds); 头文件 #include <windows.h> # wi ...
- [hadoop][基本原理]zookeeper场景使用
代码:https://github.com/xufeng79x/ZkClientTest 1. 简介 zookeeper的特性决定他适用到某些场景非常合适,比如典型的应用场景: 1.集群管理(Grou ...
- English——Unit 2
radiant radiate radical ideal ideology identical identification identify identity journal jounalist ...
- 手机端调试console.log,直接引入一个js文件
http://files.cnblogs.com/files/lwwen/mConsole.js 这是我写的一个原生js文件 直接引入即可,可以把html上面的需要打印的东西打印出来 <!DOC ...
- LeetCode解题报告—— Word Search & Subsets II & Decode Ways
1. Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be con ...
- Django-分頁組件
一.仿django分页功能自己实现 urls.py 1 2 3 4 5 6 7 8 9 from django.conf.urls import url from django.contrib imp ...
- 光流optical flow基本原理与实现
光流(optical flow)是什么呢?名字很专业,感觉很陌生,但本质上,我们是最熟悉不过的了.因为这种视觉现象我们每天都在经历.从本质上说,光流就是你在这个运动着的世界里感觉到的明显的视觉运动(呵 ...