QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722712#7883. Takeout DeliveringMocic1WA 125ms46240kbC++141.7kb2024-11-07 19:59:482024-11-07 19:59:50

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 19:59:50]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:46240kb
  • [2024-11-07 19:59:48]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=5e5+5,mod1=1e9+7,mod=998244353,inf=1e18;
typedef pair<int,int> pi;

vector<pi>v[N];

int n,m;
vector<int> dij(int x){
    vector<int>dis(n+2,inf);
    vector<int>vis(n+2,0);
    priority_queue<pi, vector<pi>, greater<pi>>q;
    q.push({0,x});
    dis[x]=0;
    while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		int x = tmp.second;
		if (vis[x])continue;
		vis[x] = 1;
		for (int i = 0; i < v[x].size(); i++) {
			if (dis[v[x][i].first] > min(dis[v[x][i].first],max(dis[x],v[x][i].second))) {
				dis[v[x][i].first] = min(dis[v[x][i].first],max(dis[x],v[x][i].second));
				q.push({dis[v[x][i].first], v[x][i].first});
			}
		}
	}
    return dis;
}
vector<pair<int,pair<int,int>>>p;
void solve(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        v[x].pb({y,z});
        v[y].pb({x,z});
        p.push_back({z,{x,y}});
    }
    vector<int>dis1=dij(1);
    vector<int>dis2=dij(n);
    int ans=1e18;
    for(auto i:p){
        int u=i.second.first;
        int v=i.second.second;
        vector<int>ww(3);
        ww[0]=i.first;
        ww[1]=dis1[u];
        ww[2]=dis2[v];
        sort(ww.begin(),ww.end());
        ans=min(ans,ww[1]+ww[2]);
        ww[0]=i.first;
        ww[1]=dis1[v];
        ww[2]=dis2[u];
        sort(ww.begin(),ww.end());
        ans=min(ans,ww[1]+ww[2]);
    }
    cout<<ans<<'\n';
}
signed main()
{
    io;
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 15524kb

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: 125ms
memory: 46240kb

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:

1356916107

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '1356916107'