题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) 满足 \(a_j = a_i\) , 则可以花费 \(b_i\) 的代价令 \(a_i\) 加一 . 若存在 \(j\) 满足 \(a_j + 1 = a_i\) , 则可以花费 \(−b_i\) 的代价令 \(a_i\) 减一 . 定义一个序列的权值为将序列中所有 \(a_i\) 变得互不相同所需…
F - The Shortest Statement emmm, 比赛的时候没有想到如何利用非树边. 其实感觉很简单.. 对于一个询问答案分为两部分求: 第一部分:只经过树边,用倍增就能求出来啦. 第二部分:经过至少一条非树边, 如果经过一个树边那么必定经过其两个端点,暴力的求出这些端点为起始点的最短路. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make…
做了四个题.. A. Vasya And Password 直接特判即可,,为啥泥萌都说难写,,,, 这个子串实际上是忽悠人的,因为每次改一个字符就可以 我靠我居然被hack了???? %……&*()(*&……好吧我把$0$从数字里扔了. /* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #in…
题目链接:The Shortest Statement 今天又在群里看到一个同学问$n$个$n$条边,怎么查询两点直接最短路.看来这种题还挺常见的. 为什么最终答案要从42个点的最短路(到$x,y$)之和,还有$x,y$到$LCA(x,y)$的距离里面取呢? 就是如果走非树边,那么一定要走42个点中的一个,不走树边,就是LCA求了. 我写的太蠢了,还写生成树,看大家都是LCA中的dfs直接标记下就行了. 验证了算法的正确,我又试了试把每条非树边只加一个点,也是AC的,其实想了想,确实正确. #i…
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树边上的点到其他任意点的最短路了. 然后对于询问x,y 先用LCA+预处理,求出树上的最短路. 接下来考虑有非树边的情况. 显然只要枚举它经过了非树边上的点z 那么用dis[z][x]+dis[z][y]尝试更新ans就好. 只要枚举非树边上的点. 这是突破口. [代码] #include <bits…
A:Vasya And Password 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #…
题目链接 传送门 题面 题意 给你一张有\(n\)个点\(m\)条边的联通图(其中\(m\leq n+20)\),\(q\)次查询,每次询问\(u\)与\(v\)之间的最短路. 思路 由于边数最多只比点数大21,因此我们可以先跑出一棵最小生成树,然后将非树上边的两个端点跑一边最短路,然后每次查询就比较\(max((dis[u]+dis[v]-2dis[lca(u,v)]),dist[i][u]+dis[i][v])\),其中\(dis[u]\)表示\(u\)到最小生成树根节点的距离,\(dist…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec Problem Description Input Output The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2). If it…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define IT set<ll>::iterator #define sqr(x)…