首页 > 其他分享 >CF1100E Andrew and Taxi

CF1100E Andrew and Taxi

时间:2023-10-20 15:55:50浏览次数:34  
标签:Taxi typedef CF1100E int lim Andrew long include define

套路题又来咯,最大值最小先直接上个二分答案\(lim\)

对于图中的边,若它的权值\(>lim\)的话这条边的方向就确定了,那么直接把这些边连出来跑个拓扑排序看看有没有环即可

如果有环则当前答案一定不合法,否则我们总存在如下的构造方法:

先把权值\(>lim\)的边得到的图的拓扑序搞出来,对于所有权值\(\le lim\)的边,如果它的起点的拓扑序大于终点,则这条边需要被反向

然后这题就做完了,总复杂度\(O(n\log c_i)\)

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_set>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=100005;
int n,m,x[N],y[N],c[N],deg[N],ord[N]; vector <int> v[N];
inline bool check(CI lim)
{
	RI i,idx=0; for (i=1;i<=n;++i) v[i].clear(),deg[i]=0;
	for (i=1;i<=m;++i) if (c[i]>lim) v[x[i]].push_back(y[i]),++deg[y[i]];
	queue <int> q; for (i=1;i<=n;++i) if (!deg[i]) q.push(i);
	while (!q.empty())
	{
		int now=q.front(); ord[now]=++idx; q.pop();
		for (auto to:v[now]) if (!--deg[to]) q.push(to);
	}
	return idx==n;
}
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (scanf("%d%d",&n,&m),i=1;i<=m;++i) scanf("%d%d%d",&x[i],&y[i],&c[i]);
	int l=0,r=1e9,mid,ret; while (l<=r)
	if (check(mid=l+r>>1)) ret=mid,r=mid-1; else l=mid+1;
	vector <int> ans; for (check(ret),i=1;i<=m;++i)
	if (c[i]<=ret&&ord[x[i]]>ord[y[i]]) ans.push_back(i);
	printf("%d %d\n",ret,ans.size());
	for (auto x:ans) printf("%d ",x);
	return 0;
}

标签:Taxi,typedef,CF1100E,int,lim,Andrew,long,include,define
From: https://www.cnblogs.com/cjjsb/p/17777284.html

相关文章

  • Taxi
    这道题很恶心,终于想通了……首先是考场做法,先模拟一下样例,猜结论。首先直觉上告诉我们:一定要尽量让牛在车上,不要空车,也就是只有到了有牛的地方或者终点才会让牛进行上车、下车的操作。然后就是车肯定至少要开牛的路程之和,然后让多出来的那部分最小。根据这个样例模拟一下最优......
  • unity中Input.GetAxis()用法
     学习笔记:usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTransformPointTest:MonoBehaviour{publicTransformCube;voidFixedUpdate(){//vector3.clampMagnitude(vector,maxlength)......
  • unity中Input.GetAxis()用法
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTransformPointTest:MonoBehaviour{publicTransformCube;voidFixedUpdate(){//vector3.clampMagnitude(vector,maxlength)//返回原向......
  • Andrew Huberman 多巴胺多巴胺 动力、专注力&满足感
    多巴胺在达到峰值之后,会在一个较低的水平进行多巴胺循环。黑质纹状体通路,主要用于运动。中层皮质边缘通路,主要用于奖励、强化和激励。多巴胺释放范围可以不同,大范围或局部(神经元之间,通过信号,在突触之间交流,多巴胺类似)都可以。通过糟糕手段大量提高多巴胺,会影响到大量释放和局......
  • S2 - Lesson 29 - Taxi
    Wordstaxi Welsh PilatusPorter roof land flat plough desert lonely     Content TaxiCaptainBenFawcetthasboughtanunusu......
  • 【计算几何】浅谈凸包Andrew算法
    前置知识基础计算几何定义。引文这样一个问题,有许多个杆子,需要用绳子围住所有的杆子,然鹅没有很多的绳子,求最短需要多少绳子。整个图大概是这样的,正文我们要如何解......
  • 创新趋势|自动驾驶出租车(Robotaxi)商业化2023年趋势展望
    本文着眼识别自动驾驶出租车(Robotaxi)商业化的核心内涵,定义商业化不同发展阶段的模式特点、能力要素和关键任务。结合中国式发展路径在生态打造和落地模式的演变提出见解......
  • CF1163F Indecisive Taxi Fee
    题意给定一张无向图,每次询问为更改一条边的边权后,从\(1\)到\(n\)的最短路。Solution首先考虑有哪些情况。如果原图中\(1\ton\)的最短路为路径\(P\),其上第\(i\)......
  • 【luogu CF1163F】Indecisive Taxi Fee(图论)(分类讨论)
    IndecisiveTaxiFee题目链接:luoguCF1163F题目大意给你一个无向图,每次改一条边的权值(每次都会变回来),问你1~n的最短路长度。思路考虑分类讨论,先找到最短路的路径,然......
  • Robotaxi商业化:合纵连横,车企掘金
    文|智能相对论作者|陈明涛当下,有多方力量已经盯上Robotaxi这块巨大的蛋糕。只是Robotaxi商业化并非一蹴而就,需要大家形成资源互补、产业协同,打造从技术研发到落地持续运营的......