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] ...
随机推荐
- VMware Workstation Pro 14 序列号
VMware Workstation Pro 14 序列号: AA702-81D8N-0817Y-75PQT-Q70A4 YC592-8VF55-M81AZ-FWW5T-WVRV0 FC78K-FKE ...
- 设计模式之Prototype
设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) 介绍: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 为什么要用Prototype ...
- 一个python拖库字段的小脚本
import requests import re all_column = dict() all_db = "db_zf,dg_activity,dg_activity_log,dg_ad ...
- Msfvenom学习总结-MSF反弹webshell
1. –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...
- 关于shutdown和close
示例代码: void str_cli(FILE *fp, int sockfd) { pid_t pid; char sendline[MAXLINE], recvline[MAXLINE]; ) { ...
- spring restTemplate 用法
发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...
- ArcGIS Server配置端口
写在前面,GIS服务器必须连通到外网,基于某些情况,可能一个机组有多态服务器,担任不同的角色,有Web服务器.数据库服务器和GIS服务器等,但是可能购买时只有一个外网IP,这样是不行的.JS脚本运行在 ...
- MyBatis3-与Spring 4集成
继续使用前一篇的例子http://www.cnblogs.com/EasonJim/p/7052368.html,实际项目中,通常会用Spring来管理DataSource等.充分利用Spring基于 ...
- php文件上传需要的配置
服务端配置(php.ini) 1.file_uploads=On //支持HTTP上传 2.upload_tmp_dir =”” //临时文件保存的目录 3.upload_max_filesize ...
- Science14年的聚类论文——Clustering by fast search and find of density peaks
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 这是一个比较新的聚类方法(文章中没看见作者对其取名,在这里我姑且称该方法为local density clu ...