QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#781341 | #7883. Takeout Delivering | zcy_qwq | WA | 144ms | 68728kb | C++14 | 3.6kb | 2024-11-25 15:46:43 | 2024-11-25 15:46:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace azcy{
using namespace std;
bool debug_switch=1;
void auto_init(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
}
void qfopen(string INPUT_FILE_NAME,string OUTPUT_FILE_NAME){
freopen(INPUT_FILE_NAME.data(),"r",stdin);
freopen(OUTPUT_FILE_NAME.data(),"w",stdout);
}
template<typename T>
void dbgo(T x){
cerr<<x<<" ";
}
template<typename First,typename... Rest>
void dbgo(First first,Rest... rest){
cerr<<first<<" ";
dbgo(rest...);
}
template<typename First,typename... Rest>
void dbg(First first,Rest... rest){
if(!debug_switch)return ;
cerr<<first<<" ";
dbgo(rest...);
cerr<<"\n";
}//made by _azcy
template<typename T>
void dbg(T x)
{
if (!debug_switch)
return;
cerr << x << "\n";
}
template<typename T>
inline T maxm(T a,T b){
return (a>b)?a:b;
}template<typename T1,typename T2>
inline T1 maxm(T1 a,T2 b){
return (a>b)?(a):(a=b,a);
}
template<typename First,typename... Rest>
inline First maxm(First first,Rest... rest){
return maxm(first,maxm(rest...));
}
template<typename T>
inline T minm(T a,T b){
return (a<b)?a:b;
}template<typename T1,typename T2>
inline T1 minm(T1 a,T2 b){
return (a<b)?a:(a=b,a);
}
template<typename First,typename... Rest>
inline First minm(First first,Rest... rest){
return minm(first,minm(rest...));
}
}using namespace azcy;
const int N=1e6+10;
#define int long long
bool m1;
pair<int,pair<int,int> > e[N];
vector<pair<int,int> > nei[N];
int fa[N];
int n,m,ans=INT_MAX,tt,dis1[N>>1],dis2[N>>1];
bool m2;
void dfs1(int id,int fa){
for(auto to:nei[id]){
if(to.first==fa) continue;
dis1[to.first]=maxm(dis1[id],to.second);
dfs1(to.first,id);
}
}void dfs2(int id,int fa){
for(auto to:nei[id]){
if(to.first==fa) continue;
dis2[to.first]=maxm(dis2[id],to.second);
dfs2(to.first,id);
}
}
int getfa(int x){
if(fa[x]==x) return x;
return fa[x]=getfa(fa[x]);
}
void merge(int x,int y){
x=getfa(x),y=getfa(y);
fa[x]=fa[y];
}
bool query(int x,int y){
x=getfa(x),y=getfa(y);
if(x==y) return 1;
else return 0;
}
void solve1(){
iota(fa+1,fa+n+2,1);
for(int i=1;i<=m;++i){
merge(e[i].second.first,e[i].second.second);
nei[e[i].second.first].push_back({e[i].second.second,e[i].first});
nei[e[i].second.second].push_back({e[i].second.first,e[i].first});
if(query(1,n)){
tt=i;
break;
}
}dfs1(1,0);
dfs2(n,0);
int w,u,v;
for(int i=1;i<=m;++i){
auto to=e[i];
w=to.first,u=to.second.first,v=to.second.second;
if(dis1[u]<=w&&dis2[v]<=w)
ans=minm(ans,maxm(dis1[u],dis2[v])+w);
swap(u,v);
if(dis1[u]<=w&&dis2[v]<=w)
ans=minm(ans,maxm(dis1[u],dis2[v])+w);
}
}
void solve2(){
// iota(fa+1,fa+n+1,1);
for(int i=1;i<=m;++i){
if((e[i].second.first==1&&e[i].second.second==n)||
(e[i].second.first==n&&e[i].second.second==1)) ans=minm(ans,e[i].first);
}
}
signed main(){
//ios::sync_with_stdio(0);
// cerr<<(&m2-&m1)/1024/1024;
auto_init();
cin>>n>>m;
for(int i=1;i<=m;++i)
cin>>e[i].second.first>>e[i].second.second>>e[i].first;
sort(e+1,e+m+1);
solve1();
cout<<ans;
}
/*
4 4
1 3 10
1 2 15
2 4 20
3 4 20
*/
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 32256kb
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: 0
Accepted
time: 138ms
memory: 68728kb
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:
1999991697
result:
ok 1 number(s): "1999991697"
Test #3:
score: -100
Wrong Answer
time: 144ms
memory: 59372kb
input:
300000 299999 207226 231742 414945003 84591 210444 175968953 46327 51582 612565723 18773 141119 82562646 76139 286963 762958587 131867 224820 928900783 215240 216181 405340417 144725 290878 195350550 267216 268752 846015171 31413 255927 389339642 45219 147512 489502910 113391 215402 555706684 53359 ...
output:
9887
result:
wrong answer 1st numbers differ - expected: '1989898633', found: '9887'