大意: 给定有向图, 每条边有一个权值, 假设你有$x$个控制器, 那么可以将所有权值不超过$x$的边翻转, 求最少的控制器数, 使得翻转后图无环

先二分转为判定问题. 每次check删除能动的边, 若剩余图有环显然不成立, 否则将剩余的图拓排一下, 再把能动的边按拓排的方向即可保证无环.

#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define hr cout<<'\n'
#define pb push_back
#define mid ((l+r)>>1)
#define lc (o<<1)
#define rc (lc|1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false);
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){b?exgcd(b,a%b,d,y,x),y-=a/b*x:x=1,y=0,d=a;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 4e5+10, INF = 0x3f3f3f3f;
int n, m;
struct _ {int u,v,w;}e[N];
vector<int> g[N];
int deg[N], s[N]; int chk(int x) {
REP(i,1,n) g[i].clear(),deg[i]=0;
REP(i,1,m) {
if (e[i].w>x) {
g[e[i].u].pb(e[i].v);
++deg[e[i].v];
}
}
queue<int> q;
*s = 0;
REP(i,1,n) if (!deg[i]) q.push(i),s[i]=++*s;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v:g[u]) {
if (!--deg[v]) q.push(v),s[v]=++*s;
}
}
REP(i,1,n) if (deg[i]) return 0;
return 1;
} int main() {
scanf("%d%d", &n, &m);
REP(i,1,m) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
int l = 0, r = 1e9, ans;
while (l<=r) {
if (chk(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
chk(ans);
vector<int> path;
REP(i,1,m) {
if (e[i].w<=ans&&s[e[i].u]>s[e[i].v]) {
path.pb(i);
}
}
printf("%d %d\n",ans,int(path.size()));
for (int i:path) printf("%d ",i);hr;
}

Andrew and Taxi CodeForces - 1100E (思维,拓扑)的更多相关文章

  1. E - E CodeForces - 1100E(拓扑排序 + 二分)

    E - E CodeForces - 1100E 一个n个节点的有向图,节点标号从1到n,存在m条单向边.每条单向边有一个权值,代表翻转其方向所需的代价.求使图变成无环图,其中翻转的最大边权值最小的方 ...

  2. CodeForces - 1100E 二分+拓扑排序

    题意: 一个n个节点的有向图,节点标号从1到n,存在m条单向边.每条单向边有一个权值,代表翻转其方向所需的代价.求使图变成无环图,其中翻转的最大边权值最小的方案,以及该方案翻转的最大的边权. Inpu ...

  3. CF 1100E Andrew and Taxi(二分答案)

    E. Andrew and Taxi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. CF-1100 E Andrew and Taxi

    CF-1100E Andrew and Taxi https://codeforces.com/contest/1100/problem/E 知识点: 二分 判断图中是否有环 题意: 一个有向图,每边 ...

  5. CF1100E Andrew and Taxi

    题目地址:CF1100E Andrew and Taxi 二分,每次取到一个 \(mid\) ,只保留长度 \(>mid\) 的边 dfs判环,若有环,说明 \(ans>mid\) ,否则 ...

  6. Codeforces Round #532 (Div. 2) E. Andrew and Taxi(二分+拓扑排序)

    题目链接:https://codeforces.com/contest/1100/problem/E 题意:给出 n 个点 m 条边的有向图,要翻转一些边,使得有向图中不存在环,问翻转的边中最大权值最 ...

  7. E. Andrew and Taxi(二分+拓扑判环)

    题目链接:http://codeforces.com/contest/1100/problem/E 题目大意:给你n和m,n代表有n个城市,m代表有m条边,然后m行输入三个数,起点,终点,花费.,每一 ...

  8. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  9. CF1100E Andrew and Taxi 二分答案+拓扑排序

    \(\color{#0066ff}{ 题目描述 }\) 给定一个有向图,改变其中某些边的方向,它将成为一个有向无环图. 现在求一个改变边方向的方案,使得所选边边权的最大值最小. \(\color{#0 ...

随机推荐

  1. yii2设置发送邮件的一些配置

    错误提示: Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\xampp\ht ...

  2. Linux下手工卸载11.2 RAC(非MOS的deinstall方法)

    思路来自于经典的<How to Proceed From a Failed 10g or 11.1 Oracle Clusterware (CRS) Installation (Doc ID 2 ...

  3. 怎么将Android的API demo导入到Eclipse工作区中

    File ->New Android Project 选择Create project from existing sample (不同Android版本有对应的ApiDemo示例).

  4. HTTP监视器charles入门使用教程分享---http/s packet monitors---ubuntu installation

    charles --usage http://www.cnblogs.com/chenlogin/p/5849471.html 按照Charles的提示,PC打开 chls.pro/ssl下载得到一个 ...

  5. angular自定义指令命名的那个坑

    Directive 先从定义一个简单的指令开始. 定义一个指令本质上是在HTML中通过元素.属性.类或注释来添加功能.AngularJS的内置指令都是以ng开头,如果想自定义指令,建议自定义一个前缀代 ...

  6. day12(jsp指令&内置对象&动作标签、JavaBean、EL表达式&函数库)

    day12 JSP指令 JSP指令概述 JSP指令的格式:<%@指令名 attr1="" attr2="" %>,一般都会把JSP指令放到JSP文件 ...

  7. day11(jsp入门&Cookie&HttpSession&一次性图片校验码)

    day11 JSP入门   1 JSP概述 1.1 什么是JSP JSP(Java Server Pages)是JavaWeb服务器端的动态资源.它与html页面的作用是相同的,显示数据和获取数据. ...

  8. (2.5)DDL增强功能-触发器trigger

    SQL Server:触发器详解   1. 概述 2. 触发器的分类 3. Inserted和Deleted表 4. 触发器的执行过程 5. 创建触发器 6. 修改触发器: 7. 删除触发器: 8. ...

  9. stm8s 时钟库函数选择内部RC初始化

    //本文选择16M内部RC震荡.分频为1 即系统时钟为16M void CLK_HSICmd(FunctionalState NewState) { /* Check the parameters * ...

  10. 跟我学Makefile(三)

    紧接着跟我学Makefile(二)继续学习:变量高级用法 (1)变量值的替换 :替换变量中的共有的部分,其格式是“$(var:a=b)”或是“${var:a=b}”,把变量“var”中所有以“a”字串 ...