没打,简单补档

C.Edgy Trees

容斥,把黑边断掉数联通块,每个联通块贡献$siz^k$

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,mod=1e9+;
int n,k,t1,t2,t3,tot,aset[N],siz[N];
int Finda(int x)
{
return x==aset[x]?x:aset[x]=Finda(aset[x]);
}
int Qpow(int x,int k)
{
if(k<=) return k?x:;
int tmp=Qpow(x,k>>);
return 1ll*tmp*tmp%mod*((k&)?x:)%mod;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) aset[i]=i,siz[i]=;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&t1,&t2,&t3);
if(!t3)
{
int nx=Finda(t1),ny=Finda(t2);
aset[nx]=ny,siz[ny]+=siz[nx];
}
}
for(int i=;i<=n;i++)
if(aset[i]==i) (tot+=Qpow(siz[i],k))%=mod;
printf("%d",(Qpow(n,k)-tot+mod)%mod);
return ;
}

D.Steps to One

我写的辣鸡的$O(n\log n\sqrt n)$(并跑不满),太菜了

设dp[i]表示当前为i的期望步数,暴力DP即枚举1->m从gcd转移,改为枚举gcd(指所有因子),然后莫比乌斯函数统计1->n中和某个数互质的数的个数

 #include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define vint vector<int>
#define vit vector<int>::iterator
using namespace std;
const int N=,mod=1e9+;
int dp[N],pri[N],npr[N],mul[N];
int n,t,in,cnt,ans; vint fac[N];
void Add(int &x,int y)
{
x+=y;
if(x>=mod) x-=mod;
}
int Qpow(int x,int k)
{
if(k<=) return k?x:;
int tmp=Qpow(x,k>>);
return 1ll*tmp*tmp%mod*((k&)?x:)%mod;
}
void Pre()
{
in=Qpow(n,mod-);
for(int i=;i<=n;i++)
for(int j=*i;j<=n;j+=i)
fac[j].push_back(i);
npr[]=true,mul[]=;
for(int i=;i<=n;i++)
{
if(!npr[i]) pri[++cnt]=i,mul[i]=-;
for(int j=;j<=cnt&&(t=i*pri[j])<=n;j++)
{
npr[t]=true;
if(i%pri[j]==) break;
else mul[t]=-mul[i];
}
}
}
int Count(int x,int y)//Count:for i=1 to n,gcd(i,x)==y
{
int N=n/y,X=x/y,ret=;
for(int i=;i*i<=X;i++)
if(X%i==)
{
ret+=N/i*mul[i];
if(i*i!=X) ret+=N/(X/i)*mul[X/i];
}
return ret;
}
int main()
{
scanf("%d",&n),Pre(),dp[]=;
for(int i=;i<=n;i++)
{
int tmp=n/i;
for(vit it=fac[i].begin();it!=fac[i].end();it++)
t=*it,Add(dp[i],1ll*dp[t]*Count(i,t)%mod*in%mod);
dp[i]=1ll*(dp[i]+)*Qpow(n-tmp,mod-)%mod*n%mod;
}
for(int i=;i<=n;i++) Add(ans,dp[i]);
printf("%lld",1ll*ans*in%mod);
return ;
}

呃,发现题解也不怎么快,他是用2^质因子个数容斥算的,$2^6*6$怕不是跟非常跑不满的根号差不多

E.Maximize Mex

显然答案单调不升,把每种潜力值和每个club看做左右部点,倒着加边,每次在上次的基础上继续二分图匹配到没有增广路为止

注意潜力值是从零开始的,还有每次跑完记得更新dfn

 #include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define vint vector<int>
#define vit vector<int>::iterator
using namespace std;
const int N=;
int n,m,q,t1,t2,dfn;
int val[N],bel[N],lft[N];
int del[N],vis[N],mth[N],ans[N]; vint ve[N];
bool DFS(int nde)
{
int t;
for(vit it=ve[nde].begin();it!=ve[nde].end();it++)
if(vis[t=*it]!=dfn)
{
vis[t]=dfn;
if(mth[t]==-||DFS(mth[t]))
{mth[t]=nde; return true;}
}
return false;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&val[i]);
for(int i=;i<=n;i++) scanf("%d",&bel[i]);
for(int i=;i<=m;i++) mth[i]=-; dfn=;
scanf("%d",&q);
for(int i=;i<=q;i++)
scanf("%d",&lft[i]),del[lft[i]]=true;
for(int i=;i<=n;i++)
if(!del[i]) ve[val[i]].push_back(bel[i]);
for(int i=q,mex=-;i;i--)
{
while(DFS(mex+)) mex++,dfn++; ans[i]=mex+,dfn++;
ve[val[lft[i]]].push_back(bel[lft[i]]);
}
for(int i=;i<=q;i++) printf("%d\n",ans[i]);
return ;
}

F.Dish Shopping

Codeforces Round #548的更多相关文章

  1. Codeforces Round 548 (Div. 2)

    layout: post title: Codeforces Round 548 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  2. Codeforces Round #548 (Div. 2) F splay(新坑) + 思维

    https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\), ...

  3. Codeforces Round #548 (Div. 2) E 二分图匹配(新坑) or 网络流 + 反向处理

    https://codeforces.com/contest/1139/problem/E 题意 有n个学生,m个社团,每个学生有一个\(p_i\)值,然后每个学生属于\(c_i\)社团, 有d天,每 ...

  4. CodeForces Round #548 Div2

    http://codeforces.com/contest/1139 A. Even Substrings You are given a string s=s1s2…sns=s1s2…sn of l ...

  5. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  6. C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块

    C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #548 (Div. 2) D 期望dp + 莫比乌斯反演

    https://codeforces.com/contest/1139/problem/D 题意 每次从1,m中选一个数加入队列,假如队列的gcd==1停止,问队列长度的期望 题解 概率正着推,期望反 ...

  8. C. Edgy Trees Codeforces Round #548 (Div. 2) 【连通块】

    一.题面 here 二.分析 这题刚开始没读懂题意,后来明白了,原来就是一个数连通块里点数的问题.首先在建图的时候,只考虑红色路径上的点.为什么呢,因为为了不走红色的快,那么我们可以反着想只走红色的路 ...

  9. Codeforces Round #548 (Div. 2) C. Edgy Trees

    You are given a tree (a connected undirected graph without cycles) of 

随机推荐

  1. Salesforce随笔: 将Visualforce Page导出为 Excel/CSV/txt (Display a page in Excel)

    想要实现如题所述功能,可以参照 : Visualforce Developer Guide 第57页中所举的例子,在<apex:page>标签中添加contentType属性. <a ...

  2. Linux服务器更换主板后,网卡识别失败的处理方法

    1)现象说明公司IDC机房里的一台线上服务器硬件报警,最后排查发现服务器主板坏了,随即联系厂商进行更换主板,最后更换后,登录服务器,发现网卡绑定及ip信息都在,但是ip却ping不通了,进一步排查,重 ...

  3. [LeetCode] 307. Range Sum Query - Mutable 解题思路

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  4. JS进阶系列之执行上下文

    function test(){ console.log(a);//undefined; var a = 1; } test(); 也许你会遇到过上面这样的面试题,你只知道它考的是变量提升,但是具体的 ...

  5. solr6.2单机版安装

    1安装solr服务,先安装jdk和tomcat 2去官网(http://archive.apache.org/dist/lucene/solr/)下载solr压缩包,最新版本是6.4.1,下载解压后, ...

  6. shell脚本--函数

    shell的函数和Javacript和php的函数声明一样,只不过shell在调用函数的时候,只需要写函数名就可以调用函数,注意不要在函数名后面加括号 创建并使用函数 #!/bin/bash #文件名 ...

  7. 在win10开启HyperV(Pro以上版本)安装的Docker,如何远程管理其他机器(Linux或者Win)的docker容器

    用k8s能直接管理吗? 不把那个容器加入集群,可以吗?

  8. Chrome 启动参数列表

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --type=gpu-process --channel ...

  9. 修复PLSQL Developer 与 Office 2010的集成导出Excel 功能

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.htm]"PerceivedType"="text&qu ...

  10. ArrayMap代码分析

    Java提供了HashMap,但是HashMap对于手机端而言,对内存的占用太大,所以Android提供了SparseArray和ArrayMap.二者都是基于二分查找,所以数据量大的时候,最坏效率会 ...