CodeForces 788B--Weird journey】的更多相关文章

题意:给定n个点,m条边,问能否找到多少条符合条件的路径.需要满足的条件:1.经过m-2条边两次,剩下两条边1次  2.任何两条路的终点和起点不能相同. 欧拉路的条件:存在两个或者0个奇度顶点. 思路:首先把给每条边都再增加一条边,所有点的度数都是偶数.每条边分为普通边和自环边. 1.删去两条没有公共顶点的普通边,会有四个点的度数变成奇数,不符合欧拉路. 2.删去两条有公共顶点的普通边,会有两个点的度数成为奇数,符合 2.删去一个自环边和一个普通边,会有两个点的度数成为奇数,符合 4.删去两条自…
题意: 给出无向图. good way : 仅有两条边只经过一次,余下边全经过两次的路 问你共有多少条不同的good way. 两条good way不同仅当它们所经过的边的集合中至少有一条不同 (很关键) 存在多个边连通分量的情况肯定是0. 当确定某两条边只经过一次的时候: 由于经过边的顺序不重要,余下边全经过两次,至多只有一条good way 那么把剩下经过两次的边拆分成两条经过一次的边,记现在的图是新图 原图中是否存在good way 就等价于新图中是否存在欧拉路 暴力枚举两条边判断肯定是要…
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. I…
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads in the countr…
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to vi…
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满足条件的路径数 题解: 推论:对于一条边u-->v,我们将其选作为那两条边之一,那么剩下一条边必然与之相邻或者是自环,因为这样才能满足这两条边只走1次. 那么这条边的贡献值为这条边的相邻边数+自环数,假如这条边本身为自环,那么由于剩下的边可以任选(前一个推论),贡献值为m-1 这个AC时间很6啊23…
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. I…
cf788B/789D. Weird journey 题意 n个点m条边无重边有自环无向图,问有多少种路径可以经过m-2条边两次,其它两条边1次.边集不同的路径就是不同的. 题解 将所有非自环的边变成两份.然后去掉两条边,看有没有欧拉路. 如果两条边都不是自环,那么只当他们相邻时(共享一个点),剩下的图有两个奇数度的点.有欧拉路.所以第i个点作为共享的点,有\(C(cnt_i,2)\)种路径. 如果其中一个是自环,那么其他m-1条边任意选一个都可以.有loop*(m-1)条,不过每个自环算了两次…
传送门:http://codeforces.com/contest/788/problem/B 好题!好题! 首先图不连通的时候肯定答案是0,我们下面讨论图联通的情况 首先考虑,如果我们每条边都经过两边,那么肯定是可行的 因为这样相当于把每条边复制一遍,然后问图中是否存在欧拉路径 既然每条边都出现了两遍,那么所有点的度数一定都是偶数,所以肯定有欧拉路径 现在考虑将某两条边变成出现一遍,这样的话可能会有一些点的度数变成奇数 如果我们把两条非自环的边变成出现一遍,并且这两条边不交于同一个点,那么就会…
大意:$n$结点$m$条边无向图, 满足 $(1)$经过$m-2$条边$2$次 $(2)$经过其余$2$条边$1$次 的路径为好路径, 求所有好路径数 相当于边加倍后再删除两条边, 求欧拉路条数 首先欧拉路径存在等价于奇数度点不超过2个 所以删除自环边一定成立,若删除两条非自环边, 则两边必须有公共点 特判下不连通输出0即可 #include <iostream> #include <algorithm> #include <cstdio> #define REP(i,…
[题目链接]:http://codeforces.com/problemset/problem/789/D [题意] 给你n个点,m条边; 可能会有自环 问你有没有经过某两条边各一次,然后剩余m-2条边,每条边各2次的 遍历方案,有的话输出方案数 [题解] /* 把每条边都复制一条相同的边; 然后问题就能转化为在2*m条边中,去掉两条边; 然后使得剩下的图能够进行一笔画(每条边都只经过一次) 则使奇点的个数为0或为2就好了; 考虑自环边和普通边; 对于普通边来说: ①如果删掉的两条普通边是不相邻…
考虑这个二元组中有一者是自环,则必然合法. 考虑这两条边都不是自环,如果它们不相邻,则不合法,否则合法. 坑的情况是,如果它是一张完整的图+一些离散的点,则会有解,不要因为图不连通,就误判成无解. #include<cstdio> #include<iostream> using namespace std; typedef long long ll; ll ans; int n,m,zihuan; int v[2000010],next[2000010],first[200001…
Codeforces 题面传送门 & 洛谷题面传送门 神仙题,做了我整整 2.5h,写篇题解纪念下逝去的中午 后排膜拜 1 年前就独立切掉此题的 ymx,我在 2021 年的第 5270 个小时 A 掉此题,而 ymx 在 2020 年的第 5270 就已经 A 掉了此题 %%%%%% 首先注意到一件事情,就是如果存在一个长度为 \(k\) 的 Journey,那么必然存在一个长度为 \(k\) 的 Journey,满足相邻两个字符串长度的差刚好为 \(1\)(方便起见,在后文中我们及其为 Co…
题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city,…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Irina arrived to one of the most famous cities of Berland - the Berlatov city. There are n showplaces in the city, numbered from 1 to n…
简单题. 删去结尾的不是$0$的数字,保证结尾连续的$k$个都是$0$,如果不能做到,就保留一个$0$. #include<map> #include<set> #include<ctime> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #in…
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61845295 题目大意 给定n个点m条边的无向图,不同点之间只有一条边,但可以有自环,求本质不同的合法路径的总数 一条合法路径是指经过m-2条边恰好2次,2条边1次 两条路径不同指存在一条边在两种路径中经过的次数不同 input 第一行两个整数n,m 接下来m行每行两个整数u,v,表示u到v有一条边 output 一个整数表示答案 hint 1<=n…
总共有n个节点,m条路径,要求其中m-2条路径走两遍,剩下2条路径仅走一遍,问不同的路径总数有多少,如果仅走一遍的两条边不同则将这两条路径视为不同. 可以把每条边都拆成两条重边,每条边的度数都是偶数了,那么就相当于从图中删去两条边且剩下的图中存在欧拉路经 欧拉路经存在的话就是图连通且每个点的度数都是偶数或只有两个点的度数是奇数,所以删边有如下情况 1.删两条自环 2.删一条自环和一条普通边 3.删两条有公共点的普通边 于是直接暴力统计即可,复杂度\(O(n)\) //minamoto #incl…
给定一张 $n$ 个点 $m$ 条无向边的图(无重边) :定义一种行走方案为:$m-2$ 条边走 $2$ 次,其余 $2$ 条边只走一次. 两个行走方案不同,当且仅当走一次的两条边中有不同的. 一条边走两次不好处理,可以将每条无向边拆开,然后将问题转换成:有多少种方案使得图中两条边不走的一笔画? 我们知道,对于无向图一笔画的条件是度数为奇数的点不能超过两个,而我们将所有无向边都拆成两个无向边时所有点度数肯定都是偶数的. 因为所有点度数都是偶数,所以如果拆掉一条边,一定会使这条边相连两点度数都变成…
Weird journey 题目链接:http://codeforces.com/contest/788/problem/B 数据范围:略. 题解: 我们发现就是要求,把每条无向边拆成两条无向边,其中有两条拆成一条,问这个图有没有欧拉回路. 无向图欧拉回路的充要条件是度数为奇数的点数等于$0$或者$2$. 那么我们的删边方式就分成了三种: 第一种,删任意两个自环. 第二种,删一个自环和任意一条边. 第三种,删两条有公共端点的边, 随便枚举一下就行. 代码: #include <bits/stdc…
人傻不会B 写了C正解结果因为数组开小最后RE了 疯狂掉分 AC:A Rank:392 Rating: 2191-92->2099 A. Functions again 题目大意:给定一个长度为n的数组,求最大的,其中1<=l<r<=n.(n<=10^5) 思路:按左端点所在位置的奇偶性分开计算即可. #include<cstdio> #include<algorithm> using namespace std; #define ll long lo…
来自FallDream的博客,未经允许,请勿转载,谢谢. ------------------------------------------------------ A.Anastasia and pebbles 你有两个口袋,每种口袋最多只能装k个物品,有n种物品,每种物品有ai个,两种不同的物品不能混在一起,问最少要装多少次. 题解:............. #include<iostream> #include<cstdio> #include<cmath>…
目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/contest/779/problem/A 题意:有A组和B组,每组有n个人,A组里面每个人的分值为\(a_i\),B组里面每个人的分值为\(b_i\),\(1\le a_i ,b_i\le5\),至少双方要交换多少人才能使使A组里面每种分值的人要和B组里面一样多. 思路:如果两个在\(i\)这个分值上…
Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其实就是问你得用多少次框,然后把多少次除以2就好了.每次装k的物品装回去就好了. 代码: #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; int a[maxn],n,k; int main(){ scanf(&…
图论 D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia…
  计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), sizeof((a))) using namespace std; int n, m, t; int main() { int i, j, x; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m)…
B. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. I…
[codeforces 293]A. Weird Game 试题描述 Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consist…
C. Journey time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other…
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…