QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307927 | #7883. Takeout Delivering | confesser | WA | 175ms | 107760kb | C++17 | 1.4kb | 2024-01-19 11:31:39 | 2024-01-19 11:31:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
const int N=1e6+3;
array<int,3> e[N];
struct dsu{
int f[N],k,a[N];
vi s[N];
void init(int n,int m){
F(i,1,n){
f[i]=i;
s[i].pb(i);
}
k=m;
}
int gf(int x){
return f[x]==x?x:f[x]=gf(f[x]);
}
void mg(int x,int y,int w){
x=gf(x),y=gf(y);
if(x==y) return;
if(y==gf(k)) swap(x,y);
if(x==gf(k)){
for(int i:s[y]){
assert(!a[i]);
a[i]=w;
}
}
if(si(s[x])<si(s[y])) swap(s[x],s[y]);
for(int i:s[y]) s[x].pb(i);
f[y]=x;
}
int same(int x,int y){
return gf(x)==gf(y);
}
}p,q;
int main(){
cin.tie(0)->ios::sync_with_stdio(0);
int n,m;
cin>>n>>m;
F(i,1,m) cin>>e[i][0]>>e[i][1]>>e[i][2];
sort(e+1,e+m+1,[](auto a,auto b){
return a[2]<b[2];
});
p.init(n,1);
q.init(n,n);
int ans=2e9;
F(i,1,m){
if(i==m&&ans==2e9){
cout<<p.same(1,n);
}
int u=e[i][0],v=e[i][1],w=e[i][2];
if(p.same(1,u)&&q.same(v,n)){
int mx=max(p.a[u],q.a[v]);
ans=min(ans,mx+w);
}
p.mg(u,v,w);
q.mg(u,v,w);
if(p.same(1,n)) ans=min(ans,w*2);
}
cout<<ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 60976kb
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: 175ms
memory: 107760kb
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:
01999991697
result:
wrong output format Expected integer, but "01999991697" found