Codeforces 1038E Maximum Matching
可能写了个假算法
假设定义:含有一个欧拉路的图为类欧拉图
欧拉路的定义:一个无向连通图中,存在一条路径对所有边都遍历且仅遍历一次;判断方法:该连通图中度为奇数的点的个数不能超过2,即为0或者2
题目解法:
对每一条数据a,b,c,想象成a点与b点之间连了一天值为c的边,则此图共有4个点
问题变成求图中一个合法的类欧拉图的边权和最大值
此值等于任意一个连通图的边权值之和,但一种情况除外,即此图中度为奇数的点个数超过2,对应此题中,度为奇数的点的个数即为4,此时连通图的所有边权和大于此图中合法的类欧拉图的边权和最大值,其之间的差值为图中一条边的权值,此边需要满足的条件为:如果这个连通图减去这条边,则可以形成一个合法的类欧拉图即可,此边的最小权值即为代码中的mx
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
#include<random>
#include <ctime>
#include <cassert>
#include <complex>
#include <cstring>
#include <chrono>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const int mod=1e9+;
const int maxn=1e5+;
const int maxm=1e5+;
const double eps=1e-;
int m,n;
int ar[maxn];
int ans=;
int num[],sum[];
int f[][],mx=1e5+,all;
bool ma[];
pair<pair<int,int>,int> pa[maxn];
int dfs(int x)
{
all+=sum[x];
ma[x]=;
int mid = num[x]%;
for(int i=;i<=;i++){
if(f[x][i] && !ma[i])mid += dfs(i);
}
return mid;
}
void solve(int i)
{
memset(ma,,sizeof(ma));
all=;
int x= dfs(i);
all/=;
if(x==)ans=max(ans,all-mx);
else ans=max(ans, all);
}
int main()
{
scanf("%d",&n);
memset(num,,sizeof(num));
memset(sum,,sizeof(sum));
memset(f,,sizeof(f));
ans=;
for(int i=;i<n;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
sum[a]+=b;
sum[c]+=b;
num[a]++;
num[c]++;
f[a][c]++;
f[c][a]++;
pa[i]=make_pair(make_pair(a,b),c);
}
for(int i=;i<n;i++){//求mx
int a=pa[i].first.first,b=pa[i].first.second,c=pa[i].second;
if(b<mx && a!=c){
if(num[a]==||num[c]==||f[a][c]>){
mx=min(b,mx);
}
else{
f[a][c]--;
f[c][a]--;
memset(ma,,sizeof(ma));
dfs(a);
if(ma[c])mx=min(mx,b);
f[c][a]++;
f[a][c]++;
}
}
}
//cout<<"mx = "<<mx<<endl; for(int i=;i<=;i++)solve(i); printf("%d\n",ans); return ;
}
Codeforces 1038E Maximum Matching的更多相关文章
- [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...
- [codeforces 508E]Maximum Matching
题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个 ...
- CF#508 1038E Maximum Matching
---题面--- 题解: 感觉还是比较妙的,复杂度看上去很高(其实也很高),但是因为n只有100,所以还是可以过的. 考虑一个很暴力的状态f[i][j][x][y]表示考虑取区间i ~ j的方格,左右 ...
- Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...
- Codeforces 1038 E - Maximum Matching
E - Maximum Matching 思路: 欧拉图 定理:一个度数为奇数的点的个数小于等于2的联通图存在欧拉回路 对于这道题目的图,点的个数为4,所以最坏的情况下4个点的度数都为奇数,在这种情况 ...
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces B.Maximum Absurdity 解题报告
题目链接:http://codeforces.com/contest/332/problem/B 题意:在一个序列中,在所有长度为k的区间里找出两个不重叠的最大和,输出这两个最大和所对应的开头的位置a ...
- Codeforces 484B Maximum Value(排序+二分)
题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...
随机推荐
- [LINUX]警告:检测到时钟错误。您的创建可能是不完整的。
[LINUX]警告:检测到时钟错误.您的创建可能是不完整的. 原因: 如果上一次编译时为20071001,你把系统时间改成20070901后再编译就会报这样的错误. 解决: 把时间 ...
- SPOJ Distinct Substrings(后缀数组求不同子串个数,好题)
DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its dist ...
- [BZOJ1921] [CTSC2010]珠宝商
Description Input 第一行包含两个整数 N,M,表示城市个数及特征项链的长度. 接下来的N-1 行, 每行两个整数 x,y, 表示城市 x 与城市 y 有直接道路相连.城市由1~N进行 ...
- [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- BZOJ2753 [SCOI2012]滑雪与时间胶囊 【kruskal】
题目链接 BZOJ2753 题解 完了我连\(kruskal\)裸题都做不出来了.. 题目是求最小树形图,即有向图最小生成树 我们不能直接上\(kruskal\),而要保证先加入前面的点, 所以我们排 ...
- bzoj 5099 [POI2018]Pionek 计算几何 极角排序
[POI2018]Pionek Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 269 Solved: 80[Submit][Status][Disc ...
- Android 网络编程--上传文件及相应的参数到服务器
之前一直在做SiteCheck的项目,所用到的知识大部分都涉及到网络编程方面,所以现在有时间先把它的使用方法及一些注意事项记录下来.在这里我用两种例子让大家了解它的使用方法: (1)上传图片及相应参数 ...
- Java并发(5)- ReentrantLock与AQS
引言 在synchronized未优化之前,我们在编码中使用最多的同步工具类应该是ReentrantLock类,ReentrantLock拥有优化后synchronized关键字的性能,又提供了更多的 ...
- codeforce C. Okabe and Boxes
题目传送门 这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要 ...
- [BZOJ1026][SCOI2009]windy数 解题报告|数位dp
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 一直 ...