[ZJOJ] 5794 2018.08.10【2018提高组】模拟A组&省选 旅行
Description
Input
Output
Sample Input
Input1:
4 4
1 2 1 10
2 4 3 5
1 3 1 5
2 4 2 7
Input2:
2 2
1 2 1 3
1 2 4 6
Sample Output
Output1:
6
2 3 4 5 6 7
Output2:
3
1 2 3
Data Constraint
100%的数据 2 <= N <= 1000, 0 <= M <= 3000, 1 <= a, b <= N, 1 <= l <= r <= 10^6
题目解析
数据范围不算大,看了看题首先可以得出一个推论:答案区间一定是连续的。
所以我们只要知道区间的左右段就可以了,枚举一下就很好做了。
用并查集 + 贪心的思想,将所有边按右端点的限制大小排序,之后贪心的合并点,同时选取边,当点1和点n在同一集合内,就结束枚举,过程中记录答案。
其实有点像Kruskal的过程。
Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std; //1<=a , b<=N , 1<=l<=r<=1e6
const int MAXN = ;
const int MAXM = ; int n,m;
int ans,cnt,lft;
int fa[MAXN];
struct Edge {
int from,to;
int L,R;
} l[MAXM << ]; bool cmp(Edge x,Edge y) {
return x.R > y.R;
} int _find(int x) {
if(x == fa[x]) return x;
return fa[x] = _find(fa[x]);
} int _min(int x,int y) {
return x < y ? x : y;
} int _max(int x,int y) {
return x > y ? x : y;
} inline void add(int x,int y,int a,int b) {
cnt++;
l[cnt].from = x;
l[cnt].to = y;
l[cnt].L = a;
l[cnt].R = b;
return;
} inline void init_fa() {
for(int i = ;i <= n;i++) fa[i] = i;
return;
} inline void Dinic(int s,int t) {
for(int i = ;i <= m;i++) {
init_fa();
for(int j = ;j <= m;j++) {
if(l[j].L > l[i].L) continue;
fa[_find(l[j].from)] = _find(l[j].to);
if (_find()==_find(n)) {
if(l[j].R - l[i].L > ans - ) {
lft = l[i].L;
ans = l[j].R - l[i].L + ;
}
break;
}
}
}
return;
} int main() {
scanf("%d%d",&n,&m);
int x,y,a,b;
for(int i = ;i <= m;i++) {
scanf("%d%d%d%d",&x,&y,&a,&b);
add(x,y,a,b);
}
for(int i = ;i <= n;i++ ){
fa[x] = x;
}
sort(l+,l++m,cmp);
Dinic(,n);
printf("%d\n",ans);
for(int i = lft;i<=lft + ans - ;i++) {
printf("%d ",i);
}
return ;
}
[ZJOJ] 5794 2018.08.10【2018提高组】模拟A组&省选 旅行的更多相关文章
- 新手C#SQL Server使用记录2018.08.10
主键(PrimaryKey):主键就是每个数据行(记录)的唯一标识,不会有重复值的列(字段)才能当做主键.一个表可以没有主键,但是这样会很难处理表,因此一般情况表都要设置主键. 主键有两张选用策略,分 ...
- 2018.08.10【省赛&提高A组模拟】比赛总结
题解 这次题目可真是太难了! 糟糕的运气使我AK的步伐寸步难行(士气严重下降). T1 这题还是比较水的(尽管我比赛时只拿了50分) 一些大佬们说:这题只是一道简单的暴力题,枚举l+二分r 就可以了. ...
- [jzoj 5770]【2018提高组模拟A组8.6】可爱精灵宝贝 (区间dp)
传送门 Description Branimirko是一个对可爱精灵宝贝十分痴迷的玩家.最近,他闲得没事组织了一场捉精灵的游戏.游戏在一条街道上举行,街道上一侧有一排房子,从左到右房子标号由1到n. ...
- JZOJ5857 【NOIP提高组模拟A组2018.9.8】没有上司的舞会
题目 Description "那么真的有果尔德施坦因这样一个人?"他问道. "是啊,有这样一个人,他还活着.至于在哪里,我就不知道了." "那么那个 ...
- 2018.08.10 atcoder No Need(线性dp)
传送门 输入一个序列an" role="presentation" style="position: relative;">anan,输入k&q ...
- 2018.08.10 atcoder Median Sum(01背包)
传送门 题意简述:输入一个数组an" role="presentation" style="position: relative;">anan. ...
- Cheatsheet: 2018 08.01 ~ 2018 10.31
Other Building the Ultimate Developer PC 3.0 - The Parts List for my new computer, IronHeart Face re ...
- 【JZOJ4790】【NOIP2016提高A组模拟9.21】选数问题
题目描述 在麦克雷的面前有N个数,以及一个R*C的矩阵.现在他的任务是从N个数中取出R*C个,并填入这个矩阵中.矩阵每一行的法值为本行最大值与最小值的差,而整个矩阵的法值为每一行的法值的最大值.现在, ...
- 2018.12.08【NOIP提高组】模拟B组总结(未完成)
2018.12.08[NOIP提高组]模拟B组总结 diyiti 保留道路 进化序列 B diyiti Description 给定n 根直的木棍,要从中选出6 根木棍,满足:能用这6 根木棍拼出一个 ...
随机推荐
- UIViewController 专题
呵呵 轻轻巧巧 UIViewController self setNeedsStatusBarAppearanceUpdate 刷新状态栏 (内部会重新调用 prefersStatusBarHi ...
- C++ 訪问控制权限图解
基类訪问权限 类继承方式 子类訪问权限 public public protected public protected private No Access p ...
- MyEclipse中加入web项目到tomcat
假设导入不是在MyEclipse下建立的web项目,想加入到tomcat中时,会显示"No projects are available for deployment to this ser ...
- 360p以上
请选择200MB以内,360p以上,时长3秒到300秒的文件.(支持格式:mp4.3gp.avi.mov.m4v.mkv文件)
- ClipboardEvent.clipboardData
ClipboardEvent.clipboardData https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboa ...
- Unix域套接字(Unix Domain Socket)介绍【转】
本文转载自:http://blog.csdn.net/roland_sun/article/details/50266565 版权声明:本文为博主原创文章,未经博主允许不得转载. 在Linux系统中, ...
- git subtree 拆分split repository
subtree出现,是为了取代submodule http://wenku.baidu.com/link?url=ola85Z5tIXJpxCjLTk-dcO81ayXLs68_y6dsmXIa0ni ...
- [Codeforces 485F] Oppa Funcan Style Remastered
[题目链接] https://codeforces.com/contest/986/problem/F [算法] 不难发现 , 每个人都在且仅在一个简单环中 , 设这些环长的长度分别为 A1, A2 ...
- Luogu3403跳楼机
https://zybuluo.com/ysner/note/1099616 题面 给你三个数\(x\),\(y\),\(z\),问你能够凑出多少个[1,\(h\)]之间的数. 解析 处理出\(y\) ...
- uoj#34
模板 #include<bits/stdc++.h> #define pi acos(-1) using namespace std; ; int n, m, L, x; int r[N] ...