QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278075#7883. Takeout DeliveringCryingWA 141ms40072kbC++171.6kb2023-12-07 11:34:102023-12-07 11:34:12

Judging History

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

  • [2023-12-07 11:34:12]
  • 评测
  • 测评结果:WA
  • 用时:141ms
  • 内存:40072kb
  • [2023-12-07 11:34:10]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 3e5+10,MAXM = 1e6+10,INF = 2e9+10;
typedef array<int,2> pr;
typedef array<int,3> tr;
void tomin(int& x,int y){x=min(x,y);}
int n,m,ans=INF;
tr e[MAXM];
vector<pr>t[MAXN];
int fa[MAXM],f[MAXN],g[MAXN],suf[MAXM],tag[MAXM];

int find(int x){
	return (fa[x]==x) ? (x) : (fa[x]=find(fa[x]));
}

void dfs(int u,int fa,int* f,int val){
	f[u]=val;
	for(auto [v,w]:t[u])if(v^fa){
		dfs(v,u,f,max(val,w));
	}
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);

	cin>>n>>m;
	rep(i,1,m)cin>>e[i][1]>>e[i][2]>>e[i][0];
	sort(e+1,e+1+m);
	rep(i,1,n)fa[i]=i;

	rep(i,1,m){
		int u=e[i][1],v=e[i][2];
		if(u>v)swap(u,v);
		if(u==1 && v==n){
			tomin(ans,e[i][0]);
		}
		if(find(u) != find(v)){
			fa[find(u)] = find(v);
			t[u].push_back({v,i});
			t[v].push_back({u,i});
		}
	}

	dfs(1,0,f,0);
	dfs(n,0,g,0);

	iota(fa+1,fa+m+2,1);

	rep(i,1,m)suf[i]=INF;
	rep(i,1,m){
		int u=e[i][1],v=e[i][2];
		int L=min(max(f[u],g[v]),max(f[v],g[u]));
		int R=min(max(f[u],f[v]),max(g[u],g[v]));
		for(int pos=find(L);pos<R;pos=find(pos)){
			fa[pos]=pos+1;
			suf[pos]=e[i][0];
		}
	}	
	rep(i,1,m){
		tomin(ans,e[i][0] + suf[i]);
	}

	assert(ans^INF);
	cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 10676kb

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
Wrong Answer
time: 141ms
memory: 40072kb

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:

-2147475205

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '-2147475205'