QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605047#7883. Takeout DeliveringHTensor#WA 301ms50952kbC++231.8kb2024-10-02 15:13:332024-10-02 15:13:34

Judging History

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

  • [2024-10-02 15:13:34]
  • 评测
  • 测评结果:WA
  • 用时:301ms
  • 内存:50952kb
  • [2024-10-02 15:13:33]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
#define SZ(x) ((int)(x).size())
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
using ll = long long;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

// #define MULTI_TEST
const int N = 3e5 + 5;
vpii adj[N];

void solve() {
    int n, m; cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    vector<int> vis(n + 1);
    vpii dis(n + 1);
	fill(dis.begin(), dis.end(), pair(inf, inf));

    priority_queue<
        array<int, 3>,
        vector<array<int, 3>>,
        greater<array<int, 3>>
    > Q;

    dis[1] = {inf, inf}; Q.push({inf, inf, 1});

    while(!Q.empty()) {
        auto [d1, d2, u] = Q.top(); Q.pop();
		if(vis[u]) continue; 
		vis[u] = 1;

		for(auto [v, w] : adj[u]) {
            vi tt{d1, d2, w};
            sort(tt.begin(), tt.end());
            while(tt.back() == inf) tt.pop_back();
            reverse(tt.begin(), tt.end());

            pii newdis = {tt[0], inf};
            if(tt.size() > 1) newdis.second = tt[1];

			if(newdis < dis[v]) {
				dis[v] = newdis;
				Q.push({dis[v].first, dis[v].second, v});
			}
		}
	}

    int ans = 0;
    if(dis[n].first != inf) ans += dis[n].first;
    else if(dis[n].second != inf) ans += dis[n].second;
    
    cout << dis[n].first + dis[n].second << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
#ifdef MULTI_TEST
    int T; cin >> T;
#else
    int T = 1;
#endif
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

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: 213ms
memory: 32892kb

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: 0
Accepted
time: 301ms
memory: 33060kb

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:

1989898633

result:

ok 1 number(s): "1989898633"

Test #4:

score: -100
Wrong Answer
time: 257ms
memory: 50952kb

input:

300000 299999
1 118488 989720257
1 181002 810258689
1 254222 172925351
1 176703 737330574
1 218306 941887568
1 105741 645573853
1 188490 794789787
1 273997 91455946
1 214929 293300204
1 127289 600097406
1 30589 330284120
1 128954 532459734
1 163729 627033607
1 24073 718818252
1 41571 755054850
1 560...

output:

4557430889524395384

result:

wrong answer 1st numbers differ - expected: '725564985', found: '4557430889524395384'