QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781263#7883. Takeout Deliveringwang_shiRE 2ms14040kbC++143.6kb2024-11-25 15:26:542024-11-25 15:26:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 15:26:55]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:14040kb
  • [2024-11-25 15:26:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define Nai_Long return 0
#define See_Memory cerr<<abs(&M1-&M2)/1024.0/1024.0<<"MB\n"
#define See_Time cerr<<(clock()-T)*1.0/CLOCKS_PER_SEC<<"s\n"
using namespace std;
const int N=3e5+10,M=1e6+10,MOD=998244353;
bool M1;
mt19937 rng(time(0));
namespace MTool
{
	inline int Cadd(int a,int b){return a+b>=MOD?a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline void Madd(int &a,int b){a=(a+b>=MOD?a+b-MOD:a+b);}
	inline void Mdel(int &a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int &a,int b){a=1ll*a*b%MOD;}
	inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
	inline void Mmod(int &x){x=(x%MOD+MOD)%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args> inline void Madd(int &a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mdel(int &a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline void Mmul(int &a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	int ksm(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x)) if(y&1) Mmul(s,x); return s;}
}
using namespace MTool;
int n,m; 
struct Edge
{
	int u,v,w; 
	friend bool operator <(Edge x,Edge y)
	{
		return x.w<y.w;
	}
}E[M];
struct DSU
{
	int f[N];
	void Init()
	{
		for(int i=1;i<=n+n;++i) f[i]=i;
	}
	int Find(int x)
	{
		if(f[x]==x) return f[x];
		return f[x]=Find(f[x]);
	}
	int Check(int x,int y)
	{
		return Find(x)==Find(y);
	}
	void Merge(int x,int y)
	{
		x=Find(x),y=Find(y);
		f[x]=y;
	}
}D;
vector<PII> g[N]; int cnt=0; 
void Kruskal()
{
	sort(E+1,E+m+1); D.Init(); 
	for(int i=1;i<=m;++i)
	{
		int u=E[i].u,v=E[i].v,w=E[i].w;
		if(D.Check(u,v)) continue;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
		D.Merge(u,v); cnt++;
		if(cnt==n-1) break;
	}
}
int dis1[N],dis2[N];
void Dfs1(int u,int fa)
{
	for(PII k:g[u]) 
	{
		if(k.fi==fa) continue;
		dis1[k.fi]=max(dis1[u],k.se); 
		Dfs1(k.fi,u); 
	}
}
void Dfs2(int u,int fa)
{
	for(PII k:g[u]) 
	{
		if(k.fi==fa) continue;
		dis2[k.fi]=max(dis2[u],k.se); 
		Dfs2(k.fi,u); 
	}
}
void Solve()
{
	cin>>n>>m; int ans=2e9;
	for(int i=1;i<=m;++i)
	{
		int u,v,w; cin>>u>>v>>w;
		E[i]={u,v,w};
		if(u==1&&v==n) Mmin(ans,w);
		if(u==n&&v==1) Mmin(ans,w);
	}
	Kruskal(); Dfs1(1,0); Dfs2(n,0);
	for(int i=1;i<=m;++i)
	{
		int u=E[i].u,v=E[i].v,w=E[i].w;
		if(dis1[u]<=w&&dis2[v]<=E[i].w) Mmin(ans,max(dis1[u],dis2[v])+w);
		if(dis1[v]<=w&&dis2[u]<=E[i].w) Mmin(ans,max(dis1[v],dis2[u])+w);
	}
	cout<<ans<<'\n';
}
bool M2;
int main()
{
//	freopen("takeout.in","r",stdin);
//	freopen("takeout.out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int T=clock();
	int t=1; //cin>>t;
	while(t--) Solve();
	See_Memory; See_Time;
	Nai_Long;
}







Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14040kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Runtime Error

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:


result: