QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781293#7883. Takeout Deliveringpcc1Compile Error//C++141.3kb2024-11-25 15:34:112024-11-25 15:34:11

Judging History

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

  • [2024-11-25 15:34:11]
  • 评测
  • [2024-11-25 15:34:11]
  • 提交

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];
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(dis[u],e[i].w);
		dfs(v,u);
	}
}
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)ans+=a[i].w;
		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";
	}
	cout<<ans<<"\n";
	return 0;
}



詳細信息

answer.code: In function ‘void add(int, int, int)’:
answer.code:17:13: error: ‘tot’ was not declared in this scope
   17 |         e[++tot].nxt=head[a];
      |             ^~~
answer.code:17:22: error: ‘head’ was not declared in this scope
   17 |         e[++tot].nxt=head[a];
      |                      ^~~~
answer.code: In function ‘void dfs(int, int)’:
answer.code:31:19: error: ‘head’ was not declared in this scope
   31 |         for(int i=head[u];i;i=e[i].nxt){
      |                   ^~~~
answer.code:34:29: error: ‘dis’ was not declared in this scope; did you mean ‘div’?
   34 |                 dis1[v]=max(dis[u],e[i].w);
      |                             ^~~
      |                             div
answer.code: In function ‘int main()’:
answer.code:48:24: error: ‘cmp’ was not declared in this scope; did you mean ‘bcmp’?
   48 |         sort(a+1,a+m+1,cmp);
      |                        ^~~
      |                        bcmp
answer.code:51:25: error: ‘ans’ was not declared in this scope; did you mean ‘ans2’?
   51 |                 if(x!=y)ans+=a[i].w;
      |                         ^~~
      |                         ans2
answer.code:58:21: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘1.0e+18’ to ‘2147483647’ [-Woverflow]
   58 |         int ans=1e18+10;
      |                 ~~~~^~~