Codeforces 1038 E - Maximum Matching
思路:
欧拉图
定理:一个度数为奇数的点的个数小于等于2的联通图存在欧拉回路
对于这道题目的图,点的个数为4,所以最坏的情况下4个点的度数都为奇数,在这种情况下只要删去一条边就可以满足条件了
欧拉回路算法:大圈小圈法,从起点开始跑每条边,把每条遍标记一下,直到跑到某个位置不能跑了,把点如栈,最后倒着输出
所以枚举删掉的边,跑联通图,最后判断联通图是否符合条件,复杂度:O(n^2)
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = ;
struct edge {
int to, w, id;
};
vector<edge> g[N];
int d[];
pii a[N];
bool vis[N], node[];
LL ans, tot = ;
void dfs(int u) {
node[u] = true;
for (int i = ; i < g[u].size(); i++) {
int id = g[u][i].id;
if(!vis[id]) {
vis[id] = true;
dfs(g[u][i].to);
tot += g[u][i].w;
}
}
}
int main() {
int n, u, v, w;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d %d %d", &u, &w, &v);
g[u].pb(edge{v, w, i});
g[v].pb(edge{u, w, i});
d[u]++;
d[v]++;
a[i].fi = u;
a[i].se = v;
}
ans = ;
for (int i = ; i <= n; i++) {
if(i != && a[i].fi == a[i].se) continue;
for (int j = ; j <= n; j++) vis[j] = false;
vis[i] = true;
d[a[i].fi] --;
d[a[i].se] --;
for (int j = ; j <= ; j++) {
tot = ;
mem(node, false);
dfs(j);
int cnt = ;
for (int k = ; k <= ; k++) if(node[k] && (d[k]&)) cnt++;
if(cnt <= )ans = max(ans, tot);
}
d[a[i].fi]++;
d[a[i].se]++;
}
printf("%lld\n", ans);
return ;
}
Codeforces 1038 E - Maximum Matching的更多相关文章
- Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...
- [codeforces 508E]Maximum Matching
题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个 ...
- [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...
- Codeforces 1038E Maximum Matching
可能写了个假算法 假设定义:含有一个欧拉路的图为类欧拉图 欧拉路的定义:一个无向连通图中,存在一条路径对所有边都遍历且仅遍历一次:判断方法:该连通图中度为奇数的点的个数不能超过2,即为0或者2 题目解 ...
- CodeForces 173C Spiral Maximum 记忆化搜索 滚动数组优化
Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × ...
- CodeForces 173C Spiral Maximum (想法、模拟)
Spiral Maximum Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- CF1038E Maximum Matching 搜索/区间DP
题目传送门:http://codeforces.com/problemset/problem/1038/E 题意:给出$N$个方块,每个方块有左右两种颜色$a,b$(可以翻转使左右两种颜色交换)和一个 ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- codeforces 484B B. Maximum Value(二分)
题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- linux的/etc/passwd、/etc/shadow、/etc/group和/etc/gshadow—关于用户和组的配置文件
1./etc/passwd 存储用户信息 [root@oldboy ~]# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bi ...
- Strom学习笔记2:Storm Maven Project-StromStack工程
1:IntelliJ新建Maven工程
- The Architecture of Open Source Applications: Berkeley DB
最近研究内存关系数据库的设计与实现,下面一篇为berkeley db原始两位作为的Berkeley DB设计回忆录: Conway's Law states that a design reflect ...
- kali meterpreter中mimikatz模块获取密码
kali这方面不说了, meterpreter也略过, 做个关于mimikatz的笔记. mimikatz模块, 能获取对方机器的密码(包括哈希和明文). 渗透模块怎么进的也不说了, 方式太多, 我用 ...
- 2018-2019-1 20189206 vim.c插件安装
vim插件安装 vim插件安装 由于今天在安装vim.c插件耗费了很多时间,配置文件一直不生效,特此记录以下安装插件的方法. 安装vim.c按照博客的方法 第一步:创建目录~/.vim 这个目录是用来 ...
- FireMonkey 源码学习(6)
(6)GetGlyph和GetBaseline TFontGlyphManager是一个抽象类,在不同平台上的实现是不同的,以Windows为例,在FMX.FontGlyphs.Win.pas文件中定 ...
- (转)MongoDB学习
(二期)25.分布式文件存储数据库MongoDB [课程25]mongod...命令.xmind96.9KB [课程25]MongoD...概念.xmind0.5MB [课程25]MongoDB简介. ...
- hihoCoder week227 Longest Subsequence
题目链接 https://hihocoder.com/contest/hiho227/problem/1 题目详解 https://hihocoder.com/discuss/question/558 ...
- [bzoj 4034][HAOI 2015]树上操作
Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中 ...
- (zhuan) Evolution Strategies as a Scalable Alternative to Reinforcement Learning
Evolution Strategies as a Scalable Alternative to Reinforcement Learning this blog from: https://blo ...