QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#690442 | #7883. Takeout Delivering | dyfhpu | WA | 244ms | 30884kb | C++17 | 1.3kb | 2024-10-30 22:11:31 | 2024-10-30 22:11:32 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define int long long
const int N=3e5+10;
int dp[N][2];
vector<pair<int,int> > v[N+10];
void solve() {
int n,m;cin>>n>>m;
for(int i=1;i<=m;i++) {
int x,y,w;cin>>x>>y>>w;
v[x].push_back({y,w});
v[y].push_back({x,w});
}
set<pair<int,int> > s;
int minn=0x3f;
s.insert({0,1});
dp[1][0]=0;
dp[1][1]=0;
while(s.size()) {
auto t=s.begin();
s.erase(t);
pair<int,int> p;
p=*t;
int x=p.second;
for(auto y:v[x]) {
int cnt=y.second;
int yy=y.first,xz=dp[x][1],yz=dp[x][0];//if(x==5) cout<<"P="<<p.first<<endl;
if(cnt>xz){
yz=xz;
xz=cnt;
}else if(cnt>yz){
yz=cnt;
}
if(dp[yy][1]==0&&dp[yy][0]==0){
dp[yy][1]=xz;
dp[yy][0]=yz;
}else{
if(dp[yy][1]+dp[yy][0]<=xz+yz)continue;
else {
dp[yy][1]=xz;
dp[yy][0]=yz;
}
}
dp[yy][1]=xz;
dp[yy][0]=yz;
// if(x==5&&yy==8) cout<<xz<<' '<<yz<<endl;
if(yy==n) {
minn=min(minn,dp[y.first][1]+dp[y.first][0]);
continue;
}
s.insert({dp[y.first][1]+dp[y.first][0],y.first});
}
}
cout<<minn<<endl;
}
signed main()
{
int t=1;
while(t--) solve();
return 0;
}
/*6 7
1 2 1
1 5 2
1 6 4
2 3 2
3 4 1
4 6 1
5 6 2*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11200kb
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: 244ms
memory: 30884kb
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:
63
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '63'