답안 #1090865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090865 2024-09-19T00:38:19 Z phong 날다람쥐 (JOI14_ho_t4) C++17
100 / 100
107 ms 24184 KB
#include<bits/stdc++.h>
#define ll long long
const int nmax = 1e5 + 5, N = 1e5;
const ll oo = 1e18 + 5, base = 311;
const int lg = 17,mod = 1e9 +7;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, m, X, a[nmax];
struct node{
    ll w, u, x, id;
    friend bool operator < (const node&a, const node&b){
        return a.w > b.w;
    }
};
ll dp[nmax];
vector<pii> adj[nmax];
int cnt[nmax];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("ROBOT.inp", "r", stdin);
//    freopen("ROBOT.out", "w", stdout);
    cin >> n >> m >> X;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i =1; i <= m; ++i){
        int u, v, w;
        cin >> u >> v >> w;
        if(a[u] >= w)  adj[u].push_back({w, v});
        if(a[v] >= w)adj[v].push_back({w, u});

    }
    priority_queue<pii> q;
    for(int i = 1; i <= n; ++i) dp[i] = -oo;
    dp[1] = X;
    q.push({X, 1});
    while(q.size()){
        pii tmp = q.top();q.pop();
        int u = tmp.se;
        for(auto [w,v] : adj[u]){
            if(tmp.fi - w <= a[v]){
                if(dp[v] < dp[u] - w){
                    dp[v] = dp[u] - w;
                    q.push({dp[v], v});
                }
            }
            else if(tmp.fi - w > a[v]){
                if(dp[v] < a[v]){
                    dp[v] = a[v];
                    q.push({dp[v], v});
                }
            }
        }
    }
    if(dp[n] == -oo) cout << -1;
    else cout << X - dp[n] +  abs(a[n] - dp[n]);
}
/*
3 3

899
*/

Compilation message

2014_ho_t4.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 3084 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2904 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2864 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2824 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 8020 KB Output is correct
2 Correct 94 ms 20176 KB Output is correct
3 Correct 58 ms 10544 KB Output is correct
4 Correct 97 ms 18884 KB Output is correct
5 Correct 86 ms 19656 KB Output is correct
6 Correct 4 ms 2648 KB Output is correct
7 Correct 49 ms 3956 KB Output is correct
8 Correct 98 ms 20752 KB Output is correct
9 Correct 66 ms 11344 KB Output is correct
10 Correct 39 ms 8024 KB Output is correct
11 Correct 12 ms 4736 KB Output is correct
12 Correct 62 ms 14540 KB Output is correct
13 Correct 26 ms 12884 KB Output is correct
14 Correct 53 ms 10084 KB Output is correct
15 Correct 4 ms 3160 KB Output is correct
16 Correct 85 ms 23688 KB Output is correct
17 Correct 11 ms 4444 KB Output is correct
18 Correct 11 ms 5020 KB Output is correct
19 Correct 25 ms 5776 KB Output is correct
20 Correct 13 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 3084 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2904 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2864 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2824 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 79 ms 8020 KB Output is correct
22 Correct 94 ms 20176 KB Output is correct
23 Correct 58 ms 10544 KB Output is correct
24 Correct 97 ms 18884 KB Output is correct
25 Correct 86 ms 19656 KB Output is correct
26 Correct 4 ms 2648 KB Output is correct
27 Correct 49 ms 3956 KB Output is correct
28 Correct 98 ms 20752 KB Output is correct
29 Correct 66 ms 11344 KB Output is correct
30 Correct 39 ms 8024 KB Output is correct
31 Correct 12 ms 4736 KB Output is correct
32 Correct 62 ms 14540 KB Output is correct
33 Correct 26 ms 12884 KB Output is correct
34 Correct 53 ms 10084 KB Output is correct
35 Correct 4 ms 3160 KB Output is correct
36 Correct 85 ms 23688 KB Output is correct
37 Correct 11 ms 4444 KB Output is correct
38 Correct 11 ms 5020 KB Output is correct
39 Correct 25 ms 5776 KB Output is correct
40 Correct 13 ms 5212 KB Output is correct
41 Correct 52 ms 9280 KB Output is correct
42 Correct 15 ms 5724 KB Output is correct
43 Correct 43 ms 7916 KB Output is correct
44 Correct 44 ms 11212 KB Output is correct
45 Correct 84 ms 22992 KB Output is correct
46 Correct 7 ms 4440 KB Output is correct
47 Correct 90 ms 20556 KB Output is correct
48 Correct 107 ms 21712 KB Output is correct
49 Correct 87 ms 18132 KB Output is correct
50 Correct 87 ms 24184 KB Output is correct
51 Correct 15 ms 5724 KB Output is correct
52 Correct 84 ms 17152 KB Output is correct
53 Correct 58 ms 9808 KB Output is correct
54 Correct 63 ms 11344 KB Output is correct
55 Correct 59 ms 10068 KB Output is correct
56 Correct 107 ms 22296 KB Output is correct
57 Correct 24 ms 7516 KB Output is correct
58 Correct 3 ms 3164 KB Output is correct
59 Correct 50 ms 9304 KB Output is correct
60 Correct 22 ms 7260 KB Output is correct