C. Array and Operations
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < jk ≤ n.

In one operation you can perform a sequence of actions:

  • take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
  • divide both numbers by v, i. e. perform the assignments:  and .

Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.

Input

The first line contains two space-separated integers nm (2 ≤ n ≤ 100, 1 ≤ m ≤ 100).

The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — the description of the array.

The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ikjk (1 ≤ ik < jk ≤ nik + jk is an odd number).

It is guaranteed that all the good pairs are distinct.

Output

Output the answer for the problem.

Sample test(s)
input
3 2
8 3 8
1 2
2 3
output
0
input
3 2
8 12 8
1 2
2 3
output
2

恶补网络流中
把数字奇偶分开,显然询问是1奇1偶的,那么相当于在二分图上搞了
枚举每一个质因数,建图,网络流。没了。拆点都不要
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#define LL long long
#define inf 0x3ffffff
#define S 0
#define T 99999
#define N 200010
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct edge{int to,next,v;}e[10*N];
int head[N];
int a[N],h[N],q[N],u[N],v[N];
int n,m,cnt=1,ans;
inline void ins(int u,int v,int w)
{
e[++cnt].v=w;
e[cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
}
inline void insert(int u,int v,int w)
{
ins(u,v,w);
ins(v,u,0);
}
inline bool bfs()
{
int t=0,w=1;
memset(h,-1,sizeof(h));
q[1]=S;h[S]=0;
while (t<w)
{
int now=q[++t];
for (int i=head[now];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==-1)
{
h[e[i].to]=h[now]+1;
q[++w]=e[i].to;
}
}
if (h[T]==-1)return 0;
return 1;
}
inline int dfs(int x,int f)
{
if (x==T||!f)return f;
int w,used=0;
for (int i=head[x];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==h[x]+1)
{
w=dfs(e[i].to,min(e[i].v,f-used));
e[i].v-=w;
e[i^1].v+=w;
used+=w;
if (f==used)return f;
}
if (!used)h[x]=-1;
return used;
}
inline void dinic(){while (bfs())ans+=dfs(S,inf);}
inline void solve(int x)
{
cnt=1;
memset(head,0,sizeof(head));
for (int i=1;i<=n;i++)
{
int t=0;
while (a[i]%x==0)t++,a[i]/=x;
if(i&1)insert(S,i,t);
else insert(i+n,T,t);
}
for (int i=1;i<=m;i++)insert(u[i],v[i]+n,inf);
dinic();
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)a[i]=read();
for (int i=1;i<=m;i++)
{
u[i]=read();
v[i]=read();
if (u[i]%2==0)swap(u[i],v[i]);
}
for (int i=1;i<=n;i++)
{
int t=sqrt(a[i]);
for (int j=2;j<=t;j++)if (a[i]%j==0)solve(j);
if (a[i]!=1)solve(a[i]);
}
printf("%d\n",ans);
return 0;
}

cf498C Array and Operations的更多相关文章

  1. CF498C. Array and Operations [二分图]

    CF498C. Array and Operations 题意: 给定一个长为 n 的数组,以及 m 对下标 (a, b) 且满足 a + b 为奇数,每次操作可以将同一组的两个数同时除以一个公约数 ...

  2. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  3. Array and Operations

    A. Array and Operations Time Limit: 1000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d    ...

  4. 网络流(最大流):CodeForces 499E Array and Operations

    You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m goo ...

  5. Codeforces 498C Array and Operations(最大流)

    题目是给一些数和<数对>的下标,然后进行操作:对某个<数对>中的两个数同时除以一个都能被它们整除且不等于1的数,要求的就是最多能进行多少次操作. 除数一定是素数,就是要决定某素 ...

  6. codeforcese 498C. Array and Operations 网络流

    题目链接 给n个数, m个数对, 每个数对是两个下标加起来为奇数的两个数.每次操作可以使一个数对中的两个数同时除某个数, 除的这个数是这两个数的任意约数, 问这种操作最多可以做几次.n<100, ...

  7. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配

    因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...

  8. ZOJ 3427 Array Slicing (scanf使用)

    题意  Watashi发明了一种蛋疼(eggache) 语言  你要为这个语言实现一个 array slicing 函数  这个函数的功能是 有一个数组初始为空  每次给你一个区间[ l, r)  和 ...

  9. Codeforces Round #284 (Div. 1)

    A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...

随机推荐

  1. poj 3229 The Best Travel Design ( 图论+状态压缩 )

    The Best Travel Design Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1359   Accepted: ...

  2. Laravel 加载 js css image 文件

    写在前面的话: 1.前提是需要使用blade模板引擎 2.css js image 文件夹建在laravel 的 public 目录下面 3.生成的路径默认都是相对路径 A: 加载css文件 (用下面 ...

  3. linux groupmems命令

    Because users group membership is defined in two different locations, it can be difficult to find ou ...

  4. spring通过注解依赖注入和获取xml配置混合的方式

    spring的xml配置文件中某个<bean></bean>中的property的用法是什么样的? /spring-beans/src/test/java/org/spring ...

  5. request.ServerVariables获取环境变量

    Request.ServerVariables("HTTP_X_FORWARDED_FOR")  透过代理服务器取得客户端的真实IP地址,有些用此方法读取到的仍然是代理服务器的IP ...

  6. php防止重复提交问题

    php防止重复提交问题 用户提交表单时可能因为网速的原因,或者网页被恶意刷新,致使同一条记录重复插入到数据库中,这是一个比较棘手的问题.我们可以从客户端和服务器端一起着手,设法避免同一表单的重复提交. ...

  7. 如何分析apache日志[access_log(访问日志)和error_log(错误日志)]

    如何分析apache日志[access_log(访问日志)和error_log(错误日志)] 发布时间: 2013-12-17 浏览次数:205 分类: 服务器 默认Apache运行会access_l ...

  8. smokeping报错Can't locate RRDs.pm in @INC (@INC contains

    安装完smokeping,执行debug语句: ./bin/smokeping --debug-daemon ,提示如下错误: Can't locate RRDs.pm in @INC (@INC c ...

  9. Nagios设置只监控不报警

    设置全部监控项都开启邮件报警: vim /usr/local/nagios/etc/nagios.cfg 设置 enable_notifications=1    1为开启,0为关闭     如个别监 ...

  10. Starting nagios:This account is currently not available nagios

    nagios在启动时报错 # service nagios restartRunning configuration check…done.Stopping nagios: done.Starting ...