可能写了个假算法

假设定义:含有一个欧拉路的图为类欧拉图

欧拉路的定义:一个无向连通图中,存在一条路径对所有边都遍历且仅遍历一次;判断方法:该连通图中度为奇数的点的个数不能超过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的更多相关文章

  1. [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]

    前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...

  2. [codeforces 508E]Maximum Matching

    题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个 ...

  3. CF#508 1038E Maximum Matching

    ---题面--- 题解: 感觉还是比较妙的,复杂度看上去很高(其实也很高),但是因为n只有100,所以还是可以过的. 考虑一个很暴力的状态f[i][j][x][y]表示考虑取区间i ~ j的方格,左右 ...

  4. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  5. Codeforces 1038 E - Maximum Matching

    E - Maximum Matching 思路: 欧拉图 定理:一个度数为奇数的点的个数小于等于2的联通图存在欧拉回路 对于这道题目的图,点的个数为4,所以最坏的情况下4个点的度数都为奇数,在这种情况 ...

  6. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

  7. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces B.Maximum Absurdity 解题报告

    题目链接:http://codeforces.com/contest/332/problem/B 题意:在一个序列中,在所有长度为k的区间里找出两个不重叠的最大和,输出这两个最大和所对应的开头的位置a ...

  9. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...

随机推荐

  1. Java23个设计模式的简明教程

    设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 毫无疑问,设计模式于 ...

  2. 周记【距gdoi:96天】

    倒计时从三位数变成了两位数. 然后这周还是很不知道怎么说,经常写一道题写两天.但是总算把后缀数组写完了,也整理完了. 然后周末都不知道干了什么周末就过去了.无聊看了两道省选题发现都是不会做系列,看了以 ...

  3. [Leetcode] text justification 文本对齐

    Given an array of words and a length L, format the text such that each line has exactly L characters ...

  4. 【ZJ选讲·BZOJ 5073】

    小A的咒语 给出两个字符串A,B (len<=105) 现在可以把A串拆为任意段,然后取出不超过 x 段,按在A串中的前后顺序拼接起来 问是否可以拼出B串. [题解]       ①如果遇 ...

  5. BZOJ_day5

    32题...今天颓了不想再写了

  6. Eclipse中的引用项目报Could not find *.apk!解决办法

    百度上很多关于Could not find *.apk!这种编译报错的解决帖子,但是笔主在这里主要说一下在 引用工程项目的场景 下报这个错误消息的问题(不影响本项目的正常编译运行!). 笔主刚从谷歌上 ...

  7. vector 进阶

    http://classfoo.com/ccby/article/jnevK #include <iostream> #include <vector> #include &l ...

  8. HDU 5670

    Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  9. 解读python小练习

    1.新建一个函数,判断是不是int 类型,并测试,不是抛出错误def adder(x, y):"""Return x + y if they are both integ ...

  10. ppk和pem证书互转

    首先你得去下载个putty pem:通用证书格式 ppk:为putty下面的专有格式     pem->ppk 直接通过putty下的puttygen.exe 选的Load private ke ...