QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339555 | #7883. Takeout Delivering | 275307894a# | WA | 0ms | 30604kb | C++14 | 2.0kb | 2024-02-27 15:45:54 | 2024-02-27 15:45:55 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*10+5,K=1000+5,mod=998244353,Mod=+-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int vis[N],n,m,fa[N];vector<pii> S[N];
struct edge{int x,y;ll w;}e[N];
ll mi;
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
void dfs(int x,int lim,int y){//gdb(x,lim,y);
if(vis[x]) return;vis[x]=1;
for(auto i:S[x]){
if(i.se<=lim) dfs(i.fi,lim,y);
if(GF(i.fi)==GF(y)) mi=min(mi,1ll*i.se);
}
}
void Solve(){
int i,j,h;scanf("%d%d",&n,&m);
for(i=1;i<=m;i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
sort(e+1,e+m+1,[](edge x,edge y){return x.w<y.w;});
ll ans=INF;mi=INF;iota(fa+1,fa+n+1,1);
for(i=1;i<=m;i++) S[e[i].x].emplace_back(e[i].y,e[i].w),S[e[i].y].emplace_back(e[i].x,e[i].w);
dfs(1,-1,n);dfs(n,-1,1);
ans=min(ans,mi);
for(i=1;i<=m;i=h+1){
for(h=i;h<=m;h++) if(e[i].w^e[h].w) break;
h--;
for(int j=i;j<=h;j++) fa[GF(e[j].x)]=GF(e[j].y);
if(GF(1)==GF(n)) return;
for(int j=i;j<=h;j++){
if(GF(e[j].x)==GF(1)) dfs(e[j].y,e[j].w,n);
if(GF(e[j].x)==GF(n)) dfs(e[j].x,e[j].w,1);
}
ans=min(ans,mi+e[i].w);
}
printf("%lld\n",ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 30604kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements