ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213262 | #3848. 赏花 | 18112606231 | 20 | 0ms | 2808kb | C++11 | 1.7kb | 2024-11-10 10:05:49 | 2024-11-10 13:04:40 |
answer
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int n,m,u,v,w,head[200001],dis[200001],pos,maxsize,minn=1e18,maxn;
struct edge
{
int u,v,w,next;
}e[200001];
void addedge(int u,int v,int w)
{
e[++pos]={u,v,w,head[u]};
head[u]=pos;
}
int dijstra(int s)
{
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
memset(dis,0x3f,sizeof(dis));
dis[s]=0;
q.push({0,s});
while(!q.empty())
{
int u=q.top().second;
q.pop();
for(int i=head[u];i;i=e[i].next)
{
int v=e[i].v;
if(dis[v]>dis[u]+1)
{
dis[v]=dis[u]+1;
q.push({dis[v],v});
}
}
}
return dis[n];
}
struct node
{
int x,maxn,minn,step,fa;
};
void bfs(int s)
{
queue<node>q;
q.push({s,0,1000000000000000000ll,0});
while(!q.empty())
{
node u=q.front();
q.pop();
if(u.step==maxsize)
{
if(u.x==n)
{
minn=min(minn,u.minn);
maxn=max(maxn,u.maxn);
return;
}
continue;
}
for(int i=head[u.x];i;i=e[i].next)
{
if(i!=u.fa)
q.push({e[i].v,max(u.maxn,e[i].w),min(u.minn,e[i].w),u.step+1,u.x});
}
}
}
signed main()
{
scanf("%lld%lld",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&u,&v,&w);
addedge(u,v,w);
addedge(v,u,w);
}
maxsize=dijstra(1);
bfs(1);
//cout<<maxn<<' '<<minn<<endl;
printf("%lld %lld",maxsize,maxn-minn);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 2808kb
input:
10 11 2 1 574741106 3 2 59539233 4 2 862308429 5 3 524117306 6 1 868028535 7 5 325211682 8 6 7671330...
output:
1 0
result:
ok 2 number(s): "1 0"
Test #2:
score: 5
Accepted
time: 0ms
memory: 2804kb
input:
10 15 2 1 75174859 3 1 44022787 4 3 344902330 5 3 385468404 6 3 55284058 7 4 571259734 8 1 290025036...
output:
2 668969195
result:
ok 2 number(s): "2 668969195"
Test #3:
score: 5
Accepted
time: 0ms
memory: 2808kb
input:
10 11 2 1 17549310 3 1 137754066 4 1 315298597 5 2 894276460 6 1 70207474 7 4 641548147 8 7 83616706...
output:
3 876727150
result:
ok 2 number(s): "3 876727150"
Test #4:
score: 5
Accepted
time: 0ms
memory: 2808kb
input:
10 10 2 1 717426908 3 2 251753655 4 1 471051853 5 1 263423188 6 4 86597516 7 3 838519464 8 7 4993360...
output:
4 586765809
result:
ok 2 number(s): "4 586765809"
Test #5:
score: 0
Memory Limit Exceeded
input:
1000 1976 2 1 156495505 3 1 232064065 4 2 687004650 5 1 927793228 6 1 355172463 7 2 41211061 8 4 284...
output:
result:
Test #6:
score: 0
Memory Limit Exceeded
input:
1000 1820 2 1 274442369 3 2 611018866 4 1 498854229 5 1 149160657 6 5 190596092 7 2 437183772 8 4 95...
output:
result:
Test #7:
score: 0
Memory Limit Exceeded
input:
1000 1914 2 1 682705093 3 1 401282935 4 1 471215565 5 1 147979493 6 4 524785272 7 6 450150508 8 6 30...
output:
result:
Test #8:
score: 0
Memory Limit Exceeded
input:
1000 100000 2 1 147282019 3 2 90908989 4 2 901212460 5 3 806859980 6 1 127357593 7 4 672430224 8 5 8...
output:
result:
Test #9:
score: 0
Memory Limit Exceeded
input:
1000 100000 2 1 862440900 3 1 274038631 4 2 451052457 5 2 726912459 6 2 286441136 7 4 207963194 8 2 ...
output:
result:
Test #10:
score: 0
Memory Limit Exceeded
input:
1000 100000 2 1 157424796 3 1 49817162 4 3 627538165 5 1 997527956 6 2 64365399 7 4 252244052 8 2 59...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
100000 192142 2 1 23 3 1 45 4 2 1 5 3 49 6 2 11 7 1 19 8 5 9 9 5 18 10 3 3 11 4 49 12 3 22 13 1 15 1...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
100000 197288 2 1 40 3 1 39 4 3 5 5 4 11 6 2 41 7 2 21 8 7 14 9 1 1 10 3 50 11 7 8 12 3 5 13 2 39 14...
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
100000 185947 2 1 47 3 2 24 4 2 48 5 1 14 6 1 16 7 2 47 8 5 45 9 3 20 10 5 30 11 3 8 12 2 5 13 10 48...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
100000 198555 2 1 18 3 2 12 4 3 1 5 2 43 6 5 22 7 3 33 8 5 46 9 6 6 10 3 15 11 7 50 12 8 16 13 2 6 1...
output:
result:
Test #15:
score: 0
Runtime Error
input:
100000 180838 2 1 621329386 3 2 648567834 4 3 892090214 5 3 518337384 6 4 447299965 7 5 789310908 8 ...
output:
result:
Test #16:
score: 0
Runtime Error
input:
100000 198243 2 1 640266132 3 2 535523966 4 2 964334629 5 4 30144932 6 2 370167988 7 6 408070807 8 2...
output:
result:
Test #17:
score: 0
Runtime Error
input:
100000 189081 2 1 761134421 3 1 560510240 4 2 10391619 5 1 212903081 6 4 328951976 7 4 117851203 8 7...
output:
result:
Test #18:
score: 0
Runtime Error
input:
100000 182605 2 1 540097606 3 2 131508099 4 2 806008577 5 1 572768389 6 3 677414662 7 6 166795991 8 ...
output:
result:
Test #19:
score: 0
Runtime Error
input:
100000 193540 2 1 715451778 3 2 31499974 4 2 547284294 5 4 564502651 6 3 873424178 7 5 151484960 8 4...
output:
result:
Test #20:
score: 0
Runtime Error
input:
100000 185722 2 1 324871956 3 1 830540294 4 3 706966347 5 1 662569628 6 4 500783123 7 2 310955607 8 ...