QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666304 | #7883. Takeout Delivering | hellocccl | TL | 1ms | 5660kb | C++20 | 1.8kb | 2024-10-22 17:41:20 | 2024-10-22 17:41:31 |
Judging History
answer
//ALL IN
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#define double long double
const int N=3e5+7;
const int inf=4e18;
vector<pair<int,int>>g[N];
int n,m;
int vis[N][2];
void dfs(int x,int fa,int used,int one,int two){
// cout<<"?"<<x<<" "<<fa<<" "<<used<<'\n';
vis[x][used]=1;
if(x==n){
return;
}
for(auto [y,w]:g[x]){
if(y==fa)continue;
if(w<=two){
if(!vis[y][0])
dfs(y,x,0,one,two);
}else if(w<=one){
if(used==1)continue;
if(!vis[y][1])
dfs(y,x,1,one,two);
}
}
}
bool check(int one ,int two){
for(int i=1;i<=n;i++)vis[i][0]=vis[i][1]=0;
//判断最大是one 次大是two能不能使得1去往n
dfs(1,0,0,one,two);
if(vis[n][0]==1 or vis[n][1]==1)return 1;
return 0;
}
void solve(){
cin>>n>>m;
int mx=0;
for(int i=1;i<=m;i++){
int u,v,w;cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
mx=max(mx,w);
}
int ans=inf;
int l=0,r=mx+1;
while(l+1!=r){
int mid=l+r>>1;
int ll=-1,rr=mid+1;
int flag=0;
while(ll+1!=rr){
// cout<<"?"<<l<<" "<<r<<" "<<ll<<" "<<rr<<'\n';
int midmid=ll+rr>>1;
// cout<<mid<<" "<<midmid<<'\n';
// cout<<check(mid,midmid)<<"\n\n";
if(check(mid,midmid)){
ans=min(ans,mid+midmid);
rr=midmid;
flag=1;
}else{
ll=midmid;
}
}
if(flag)r=mid;
else l=mid;
}
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
// cin>>_;
while(_--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
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
Time Limit Exceeded
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 ...