답안 #1100568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100568 2024-10-14T09:09:29 Z vjudge1 Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
198 ms 31416 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=2e5+5, mod = 1e9+7, inf = 1e18;

int n, m, s, t, l, k;
int ds[N], dt[N];
vector<ii> adj[N];
priority_queue<ii,vector<ii>,greater<ii>> pq;

signed main() {
    //freopen("tmp.inp", "r", stdin);
    //freopen("tmp.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> s >> t >> l >> k;
    
    for(int i=1; i<=m; i++) {
        int a, b, c; cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    
    for (int i=1; i<=n; i++) ds[i] = inf;
    ds[s] = 0; pq.push({0, s});
    while(!pq.empty()) {
        int u = pq.top().se, d = pq.top().fi; pq.pop();
        if(d>ds[u]) continue;
        for (auto [v, w]: adj[u]) {
            if(ds[v]>ds[u]+w) {
                ds[v] = ds[u]+w;
                pq.push({ds[v], v});
            }
        }
    }

    for (int i=1; i<=n; i++) dt[i] = inf;
    dt[t] = 0; pq.push({0, t});
    while(!pq.empty()) {
        int u = pq.top().se, d = pq.top().fi; pq.pop();
        if(d>dt[u]) continue;
        for (auto [v, w]: adj[u]) {
            if(dt[v]>dt[u]+w) {
                dt[v] = dt[u]+w;
                pq.push({dt[v], v});
            }
        }
    }
    for(int i=1; i<=n; i++) {
        if(ds[i]+dt[i]<=k) {
            cout << n*(n-1)/2;
            return 0;   
        }
    }
    int ans = 0;
    sort(ds+1, ds+n+1); sort(dt+1, dt+n+1);
    for(int i=1; i<=n; i++) {
        int pos = upper_bound(dt+1, dt+n+1, k-l-ds[i])-dt-1;
        ans += pos;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6740 KB Output is correct
2 Correct 2 ms 6800 KB Output is correct
3 Correct 2 ms 6904 KB Output is correct
4 Correct 2 ms 6740 KB Output is correct
5 Correct 3 ms 6996 KB Output is correct
6 Correct 2 ms 6996 KB Output is correct
7 Correct 66 ms 23672 KB Output is correct
8 Correct 72 ms 23860 KB Output is correct
9 Correct 68 ms 23584 KB Output is correct
10 Correct 2 ms 6740 KB Output is correct
11 Correct 2 ms 6740 KB Output is correct
12 Correct 2 ms 6740 KB Output is correct
13 Correct 3 ms 6996 KB Output is correct
14 Correct 36 ms 14932 KB Output is correct
15 Correct 127 ms 22224 KB Output is correct
16 Correct 2 ms 6904 KB Output is correct
17 Correct 2 ms 6740 KB Output is correct
18 Correct 80 ms 20556 KB Output is correct
19 Correct 2 ms 6740 KB Output is correct
20 Correct 2 ms 6740 KB Output is correct
21 Correct 3 ms 6740 KB Output is correct
22 Correct 5 ms 6996 KB Output is correct
23 Correct 43 ms 14932 KB Output is correct
24 Correct 125 ms 22048 KB Output is correct
25 Correct 2 ms 6740 KB Output is correct
26 Correct 3 ms 6912 KB Output is correct
27 Correct 79 ms 29880 KB Output is correct
28 Correct 60 ms 22828 KB Output is correct
29 Correct 65 ms 18764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6740 KB Output is correct
2 Correct 2 ms 6904 KB Output is correct
3 Correct 2 ms 6740 KB Output is correct
4 Correct 2 ms 6908 KB Output is correct
5 Correct 2 ms 6740 KB Output is correct
6 Correct 2 ms 6740 KB Output is correct
7 Correct 2 ms 6740 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6740 KB Output is correct
10 Correct 2 ms 6740 KB Output is correct
11 Correct 2 ms 6740 KB Output is correct
12 Correct 2 ms 6740 KB Output is correct
13 Correct 2 ms 6740 KB Output is correct
14 Correct 3 ms 6996 KB Output is correct
15 Correct 2 ms 6740 KB Output is correct
16 Correct 2 ms 6740 KB Output is correct
17 Correct 2 ms 6740 KB Output is correct
18 Correct 2 ms 6740 KB Output is correct
19 Correct 2 ms 6892 KB Output is correct
20 Correct 2 ms 6740 KB Output is correct
21 Correct 2 ms 6912 KB Output is correct
22 Correct 2 ms 6904 KB Output is correct
23 Correct 2 ms 6656 KB Output is correct
24 Correct 2 ms 6996 KB Output is correct
25 Correct 2 ms 6740 KB Output is correct
26 Correct 2 ms 6740 KB Output is correct
27 Correct 2 ms 6740 KB Output is correct
28 Correct 2 ms 6740 KB Output is correct
29 Correct 2 ms 6740 KB Output is correct
30 Correct 2 ms 6740 KB Output is correct
31 Correct 2 ms 6740 KB Output is correct
32 Correct 2 ms 6740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6740 KB Output is correct
2 Correct 2 ms 6904 KB Output is correct
3 Correct 2 ms 6740 KB Output is correct
4 Correct 2 ms 6908 KB Output is correct
5 Correct 2 ms 6740 KB Output is correct
6 Correct 2 ms 6740 KB Output is correct
7 Correct 2 ms 6740 KB Output is correct
8 Correct 2 ms 6740 KB Output is correct
9 Correct 2 ms 6740 KB Output is correct
10 Correct 2 ms 6740 KB Output is correct
11 Correct 2 ms 6740 KB Output is correct
12 Correct 2 ms 6740 KB Output is correct
13 Correct 2 ms 6740 KB Output is correct
14 Correct 3 ms 6996 KB Output is correct
15 Correct 2 ms 6740 KB Output is correct
16 Correct 2 ms 6740 KB Output is correct
17 Correct 2 ms 6740 KB Output is correct
18 Correct 2 ms 6740 KB Output is correct
19 Correct 2 ms 6892 KB Output is correct
20 Correct 2 ms 6740 KB Output is correct
21 Correct 2 ms 6912 KB Output is correct
22 Correct 2 ms 6904 KB Output is correct
23 Correct 2 ms 6656 KB Output is correct
24 Correct 2 ms 6996 KB Output is correct
25 Correct 2 ms 6740 KB Output is correct
26 Correct 2 ms 6740 KB Output is correct
27 Correct 2 ms 6740 KB Output is correct
28 Correct 2 ms 6740 KB Output is correct
29 Correct 2 ms 6740 KB Output is correct
30 Correct 2 ms 6740 KB Output is correct
31 Correct 2 ms 6740 KB Output is correct
32 Correct 2 ms 6740 KB Output is correct
33 Correct 2 ms 7008 KB Output is correct
34 Correct 3 ms 7008 KB Output is correct
35 Correct 2 ms 6752 KB Output is correct
36 Correct 3 ms 7008 KB Output is correct
37 Correct 2 ms 6752 KB Output is correct
38 Correct 2 ms 6752 KB Output is correct
39 Correct 3 ms 7008 KB Output is correct
40 Correct 3 ms 7008 KB Output is correct
41 Correct 3 ms 7008 KB Output is correct
42 Correct 2 ms 6752 KB Output is correct
43 Correct 3 ms 7008 KB Output is correct
44 Correct 3 ms 7008 KB Output is correct
45 Correct 4 ms 7008 KB Output is correct
46 Correct 4 ms 7008 KB Output is correct
47 Correct 3 ms 7008 KB Output is correct
48 Correct 3 ms 7012 KB Output is correct
49 Correct 2 ms 7008 KB Output is correct
50 Correct 4 ms 6752 KB Output is correct
51 Correct 4 ms 7008 KB Output is correct
52 Correct 4 ms 7008 KB Output is correct
53 Correct 4 ms 7008 KB Output is correct
54 Correct 5 ms 7008 KB Output is correct
55 Correct 3 ms 7008 KB Output is correct
56 Correct 3 ms 7008 KB Output is correct
57 Correct 3 ms 7008 KB Output is correct
58 Correct 3 ms 6820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6740 KB Output is correct
2 Correct 2 ms 6800 KB Output is correct
3 Correct 2 ms 6904 KB Output is correct
4 Correct 2 ms 6740 KB Output is correct
5 Correct 3 ms 6996 KB Output is correct
6 Correct 2 ms 6996 KB Output is correct
7 Correct 66 ms 23672 KB Output is correct
8 Correct 72 ms 23860 KB Output is correct
9 Correct 68 ms 23584 KB Output is correct
10 Correct 2 ms 6740 KB Output is correct
11 Correct 2 ms 6740 KB Output is correct
12 Correct 2 ms 6740 KB Output is correct
13 Correct 3 ms 6996 KB Output is correct
14 Correct 36 ms 14932 KB Output is correct
15 Correct 127 ms 22224 KB Output is correct
16 Correct 2 ms 6904 KB Output is correct
17 Correct 2 ms 6740 KB Output is correct
18 Correct 80 ms 20556 KB Output is correct
19 Correct 2 ms 6740 KB Output is correct
20 Correct 2 ms 6740 KB Output is correct
21 Correct 3 ms 6740 KB Output is correct
22 Correct 5 ms 6996 KB Output is correct
23 Correct 43 ms 14932 KB Output is correct
24 Correct 125 ms 22048 KB Output is correct
25 Correct 2 ms 6740 KB Output is correct
26 Correct 3 ms 6912 KB Output is correct
27 Correct 79 ms 29880 KB Output is correct
28 Correct 60 ms 22828 KB Output is correct
29 Correct 65 ms 18764 KB Output is correct
30 Correct 2 ms 6740 KB Output is correct
31 Correct 2 ms 6904 KB Output is correct
32 Correct 2 ms 6740 KB Output is correct
33 Correct 2 ms 6908 KB Output is correct
34 Correct 2 ms 6740 KB Output is correct
35 Correct 2 ms 6740 KB Output is correct
36 Correct 2 ms 6740 KB Output is correct
37 Correct 2 ms 6740 KB Output is correct
38 Correct 2 ms 6740 KB Output is correct
39 Correct 2 ms 6740 KB Output is correct
40 Correct 2 ms 6740 KB Output is correct
41 Correct 2 ms 6740 KB Output is correct
42 Correct 2 ms 6740 KB Output is correct
43 Correct 3 ms 6996 KB Output is correct
44 Correct 2 ms 6740 KB Output is correct
45 Correct 2 ms 6740 KB Output is correct
46 Correct 2 ms 6740 KB Output is correct
47 Correct 2 ms 6740 KB Output is correct
48 Correct 2 ms 6892 KB Output is correct
49 Correct 2 ms 6740 KB Output is correct
50 Correct 2 ms 6912 KB Output is correct
51 Correct 2 ms 6904 KB Output is correct
52 Correct 2 ms 6656 KB Output is correct
53 Correct 2 ms 6996 KB Output is correct
54 Correct 2 ms 6740 KB Output is correct
55 Correct 2 ms 6740 KB Output is correct
56 Correct 2 ms 6740 KB Output is correct
57 Correct 2 ms 6740 KB Output is correct
58 Correct 2 ms 6740 KB Output is correct
59 Correct 2 ms 6740 KB Output is correct
60 Correct 2 ms 6740 KB Output is correct
61 Correct 2 ms 6740 KB Output is correct
62 Correct 2 ms 7008 KB Output is correct
63 Correct 3 ms 7008 KB Output is correct
64 Correct 2 ms 6752 KB Output is correct
65 Correct 3 ms 7008 KB Output is correct
66 Correct 2 ms 6752 KB Output is correct
67 Correct 2 ms 6752 KB Output is correct
68 Correct 3 ms 7008 KB Output is correct
69 Correct 3 ms 7008 KB Output is correct
70 Correct 3 ms 7008 KB Output is correct
71 Correct 2 ms 6752 KB Output is correct
72 Correct 3 ms 7008 KB Output is correct
73 Correct 3 ms 7008 KB Output is correct
74 Correct 4 ms 7008 KB Output is correct
75 Correct 4 ms 7008 KB Output is correct
76 Correct 3 ms 7008 KB Output is correct
77 Correct 3 ms 7012 KB Output is correct
78 Correct 2 ms 7008 KB Output is correct
79 Correct 4 ms 6752 KB Output is correct
80 Correct 4 ms 7008 KB Output is correct
81 Correct 4 ms 7008 KB Output is correct
82 Correct 4 ms 7008 KB Output is correct
83 Correct 5 ms 7008 KB Output is correct
84 Correct 3 ms 7008 KB Output is correct
85 Correct 3 ms 7008 KB Output is correct
86 Correct 3 ms 7008 KB Output is correct
87 Correct 3 ms 6820 KB Output is correct
88 Correct 113 ms 23588 KB Output is correct
89 Correct 95 ms 23708 KB Output is correct
90 Correct 82 ms 23640 KB Output is correct
91 Correct 42 ms 20528 KB Output is correct
92 Correct 68 ms 20556 KB Output is correct
93 Correct 43 ms 15792 KB Output is correct
94 Correct 41 ms 15816 KB Output is correct
95 Correct 162 ms 24264 KB Output is correct
96 Correct 117 ms 24200 KB Output is correct
97 Correct 128 ms 22932 KB Output is correct
98 Correct 126 ms 22916 KB Output is correct
99 Correct 68 ms 22096 KB Output is correct
100 Correct 105 ms 22096 KB Output is correct
101 Correct 62 ms 20556 KB Output is correct
102 Correct 53 ms 20516 KB Output is correct
103 Correct 52 ms 15696 KB Output is correct
104 Correct 42 ms 15732 KB Output is correct
105 Correct 171 ms 24264 KB Output is correct
106 Correct 167 ms 24208 KB Output is correct
107 Correct 192 ms 31196 KB Output is correct
108 Correct 198 ms 31416 KB Output is correct
109 Correct 80 ms 23852 KB Output is correct
110 Correct 75 ms 23852 KB Output is correct
111 Correct 99 ms 19568 KB Output is correct
112 Correct 104 ms 19664 KB Output is correct