QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781619#7883. Takeout Deliveringpcc1Compile Error//C++141.7kb2024-11-25 16:40:222024-11-25 16:40:32

Judging History

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

  • [2024-11-25 16:40:32]
  • 评测
  • [2024-11-25 16:40:22]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
const int N=1e6+10;
int n,m;
struct node{
	int u,v,w;
}a[N];
struct Node{
	int fr,to,nxt,w;
}e[N*2];
int f[N],tot,head[N];
void add(int a,int b,int w){
	e[++tot].fr=a;
	e[tot].nxt=head[a];
	head[a]=tot;
	e[tot].to=b;
	e[tot].w=w;
}
int find(int x){
	if(f[x]==x)return x;
	return f[x]=find(f[x]);
}
int dis1[N],dis2[N];
void dfs(int u,int fa){
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)continue;
		dis1[v]=max(dis1[u],e[i].w);
		dfs(v,u);
	}
}
bool cmp(node a,node b){
	return a.w<b.w;
} 
signed main(){
	int ans=2e18;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		f[i]=i;
	}
	for(int u,v,w,i=1;i<=m;i++){
		cin>>a[i].u>>a[i].v>>a[i].w;
		if(a[i].u==1&&a[i].v==n){
			ans=min(ans,a[i].w);
		}
		if(a[i].u==n&&a[i].v==1){
			ans=min(ans,a[i].w);
		}
	}
	sort(a+1,a+m+1,cmp);
//	for(int i=1;i<=m;i++){
//		cout<<a[i].u<<" "<<a[i].v<<":\n";
//	}
	for(int i=1;i<=m;i++){
		int x=find(a[i].u);int y=find(a[i].v);
		if(x!=y){
			f[x]=y;
			add(a[i].u,a[i].v,a[i].w);
			add(a[i].v,a[i].u,a[i].w);
		}
	//	add(a[i].u,a[i].v);add(a[i].v,a[i].u);
	}
	dfs(1,0);
	swap(dis2,dis1);
//	for(int i=1;i<=n;i++){
//		cout<<dis2[i]<<" ";
//	}c
//	cout<<"\n";
	dfs(n,0);
	ans=2e9;
	if(n==300000){
		for(int i=1;i<=n;i++){
			cout<<dis[i]<<" ";
		}
	}
	for(int i=1;i<=m;i++){
		if(dis1[e[i].fr]<=e[i].w&&dis2[e[i].to]<=e[i].w)ans=min(ans,max(dis1[e[i].fr],dis2[e[i].to])+e[i].w);
		if(dis2[e[i].fr]<=e[i].w&&dis1[e[i].to]<=e[i].w)ans=min(ans,max(dis1[e[i].to],dis2[e[i].fr])+e[i].w);
	}
	cout<<ans<<"\n";
	return 0;
}



Details

answer.code: In function ‘int main()’:
answer.code:78:31: error: ‘dis’ was not declared in this scope; did you mean ‘div’?
   78 |                         cout<<dis[i]<<" ";
      |                               ^~~
      |                               div