QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781298#7883. Takeout Deliveringpcc1WA 0ms15760kbC++141.3kb2024-11-25 15:35:302024-11-25 15:35:31

Judging History

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

  • [2024-11-25 15:35:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15760kb
  • [2024-11-25 15:35:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
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];
int f[N],tot,head[N];
void add(int a,int b,int w){
	e[++tot].nxt=head[a];
	head[a]=tot;
	e[tot].to=b;
	e[tot].w=w;
	e[tot].fr=a;
}
int find(int x){
	if(f[x]==x)return x;
	return f[x]=find(f[x]);
}
vector<int>q;
int ans1,ans2;
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;
} 
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		f[i]=i;
	}
	for(int u,v,w,i=1;i<=m;i++){
		cin>>u>>v>>w;
		a[i].u=u;
		a[i].v=v;a[i].w=w;
	}
	sort(a+1,a+m+1,cmp);
	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);add(a[i].v,a[i].u);
	}
	dfs(1,0);
	swap(dis1,dis2);
	dfs(n,0);
	int ans=1e18+10;
	for(int i=1;i<=m;i++){
		if(dis2[e[i].fr]<=e[i].w&&dis1[e[i].to]<=e[i].w){
			ans=min(ans,e[i].w+max(dis2[e[i].fr],dis1[e[i].to]));
		}
		if(dis2[e[i].to]<=e[i].w&&dis1[e[i].fr]<=e[i].w){
			ans=min(ans,e[i].w+max(dis2[e[i].to],dis1[e[i].fr]));
		}
	}
	cout<<ans<<"\n";
	return 0;
}



详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 15760kb

input:

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

output:

0

result:

wrong answer 1st numbers differ - expected: '5', found: '0'