답안 #1088184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088184 2024-09-14T05:13:19 Z HienTD Construction Project 2 (JOI24_ho_t2) C++14
100 / 100
171 ms 29436 KB
#include <bits/stdc++.h>
using namespace std;

//#define USACO

#define             fi  first
#define             se  second
#define           TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define         ALL(v)  (v).begin(), (v).end()
#define         BIT(i)  (1LL << (i))
#define     MASK(x, i)  (((x) >> (i)) & 1)
#define      REP(i, v)  for( __typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define   FOR(i, a, b)  for(int i = (a), _b = (b); i <= _b; ++ i)
#define  FORD(i, b, a)  for(int i = (b), _a = (a); i >= _a; -- i)

const string NAME = "BAITAP";

const string name = "";

const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int mod = 998244353;

const int mxN = 2e5 + 5;

int N, M, S, T;
long long K, L;
vector<pair<int, long long>> adj[mxN];
vector<long long> dist_from_t(mxN, INF);
vector<long long> dist_from_s(mxN, INF);

void init(void){
    cin >> N >> M;
    cin >> S >> T >> L >> K;
    FOR(i, 1, M){
        int u, v;
        long long w;
        cin >> u >> v >> w;
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
    }
}

void dijkstra(const int &st, const int &ty){
    if(ty == 1){
        dist_from_s[st] = 0;
        priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
        pq.push(make_pair(dist_from_s[st], st));
        while(pq.empty() == false){
            pair<long long, int> cur = pq.top();
            pq.pop();
            if(dist_from_s[cur.se] != cur.fi) continue;
            for(pair<int, long long> v : adj[cur.se]){
                if(dist_from_s[v.fi] > dist_from_s[cur.se] + v.se){
                    pq.push(make_pair(dist_from_s[v.fi] = dist_from_s[cur.se] + v.se, v.fi));
                }
            }
        }
    }
    else{
        dist_from_t[st] = 0;
        priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
        pq.push(make_pair(dist_from_t[st], st));
        while(pq.empty() == false){
            pair<long long, int> cur = pq.top();
            pq.pop();
            if(dist_from_t[cur.se] != cur.fi) continue;
            for(pair<int, long long> v : adj[cur.se]){
                if(dist_from_t[v.fi] > dist_from_t[cur.se] + v.se){
                    pq.push(make_pair(dist_from_t[v.fi] = dist_from_t[cur.se] + v.se, v.fi));
                }
            }
        }
    }
}

void process(void){
    dijkstra(S, 1);
    dijkstra(T, 2);
    if(dist_from_s[T] <= K){
        cout << 1LL * N * (N - 1) / 2;
        return;
    }
    long long ans = 0;
    sort(dist_from_t.begin() + 1, dist_from_t.begin() + 1 + N);
    FOR(i, 1, N){
        long long ok = K - L - dist_from_s[i];
        ans += lower_bound(dist_from_t.begin() + 1, dist_from_t.begin() + 1 + N, ok + 1) - (dist_from_t.begin() + 1);
    }
    cout << ans;
//    FOR(i, 1, N){
//        cerr << dist_from_s[i] << ' ' << dist_from_t[i] << '\n';
//    }
}

signed main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
        freopen((NAME + ".INP").c_str(), "r", stdin);
        freopen((NAME + ".OUT").c_str(), "w", stdout);
    #elif defined(USACO)
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    #endif

    init();
    process();
    cerr << "\nTime elapsed: " << TIME << "s.\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 4 ms 8524 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 59 ms 21304 KB Output is correct
8 Correct 68 ms 21420 KB Output is correct
9 Correct 66 ms 22020 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 5 ms 8284 KB Output is correct
14 Correct 43 ms 15072 KB Output is correct
15 Correct 128 ms 22544 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 70 ms 20476 KB Output is correct
19 Correct 3 ms 8280 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 4 ms 8540 KB Output is correct
22 Correct 5 ms 8284 KB Output is correct
23 Correct 47 ms 14932 KB Output is correct
24 Correct 142 ms 22512 KB Output is correct
25 Correct 3 ms 8280 KB Output is correct
26 Correct 4 ms 8444 KB Output is correct
27 Correct 78 ms 27800 KB Output is correct
28 Correct 66 ms 22180 KB Output is correct
29 Correct 58 ms 19396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 5 ms 8300 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 6 ms 8284 KB Output is correct
13 Correct 3 ms 8288 KB Output is correct
14 Correct 3 ms 8304 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 4 ms 8092 KB Output is correct
21 Correct 4 ms 8284 KB Output is correct
22 Correct 4 ms 8284 KB Output is correct
23 Correct 3 ms 8304 KB Output is correct
24 Correct 3 ms 8284 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
26 Correct 4 ms 8284 KB Output is correct
27 Correct 3 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8116 KB Output is correct
30 Correct 3 ms 8240 KB Output is correct
31 Correct 4 ms 8284 KB Output is correct
32 Correct 3 ms 8304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 5 ms 8300 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 6 ms 8284 KB Output is correct
13 Correct 3 ms 8288 KB Output is correct
14 Correct 3 ms 8304 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 4 ms 8092 KB Output is correct
21 Correct 4 ms 8284 KB Output is correct
22 Correct 4 ms 8284 KB Output is correct
23 Correct 3 ms 8304 KB Output is correct
24 Correct 3 ms 8284 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
26 Correct 4 ms 8284 KB Output is correct
27 Correct 3 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8116 KB Output is correct
30 Correct 3 ms 8240 KB Output is correct
31 Correct 4 ms 8284 KB Output is correct
32 Correct 3 ms 8304 KB Output is correct
33 Correct 4 ms 8280 KB Output is correct
34 Correct 4 ms 8540 KB Output is correct
35 Correct 4 ms 8180 KB Output is correct
36 Correct 5 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 4 ms 8540 KB Output is correct
39 Correct 4 ms 8280 KB Output is correct
40 Correct 5 ms 8540 KB Output is correct
41 Correct 4 ms 8392 KB Output is correct
42 Correct 4 ms 8284 KB Output is correct
43 Correct 5 ms 8540 KB Output is correct
44 Correct 5 ms 8540 KB Output is correct
45 Correct 5 ms 8540 KB Output is correct
46 Correct 5 ms 8464 KB Output is correct
47 Correct 5 ms 8284 KB Output is correct
48 Correct 4 ms 8500 KB Output is correct
49 Correct 4 ms 8540 KB Output is correct
50 Correct 4 ms 8284 KB Output is correct
51 Correct 5 ms 8540 KB Output is correct
52 Correct 4 ms 8312 KB Output is correct
53 Correct 6 ms 8540 KB Output is correct
54 Correct 5 ms 8536 KB Output is correct
55 Correct 4 ms 8540 KB Output is correct
56 Correct 5 ms 8476 KB Output is correct
57 Correct 5 ms 8404 KB Output is correct
58 Correct 5 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 4 ms 8524 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 59 ms 21304 KB Output is correct
8 Correct 68 ms 21420 KB Output is correct
9 Correct 66 ms 22020 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 5 ms 8284 KB Output is correct
14 Correct 43 ms 15072 KB Output is correct
15 Correct 128 ms 22544 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 70 ms 20476 KB Output is correct
19 Correct 3 ms 8280 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 4 ms 8540 KB Output is correct
22 Correct 5 ms 8284 KB Output is correct
23 Correct 47 ms 14932 KB Output is correct
24 Correct 142 ms 22512 KB Output is correct
25 Correct 3 ms 8280 KB Output is correct
26 Correct 4 ms 8444 KB Output is correct
27 Correct 78 ms 27800 KB Output is correct
28 Correct 66 ms 22180 KB Output is correct
29 Correct 58 ms 19396 KB Output is correct
30 Correct 4 ms 8280 KB Output is correct
31 Correct 3 ms 8284 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 3 ms 8284 KB Output is correct
34 Correct 4 ms 8284 KB Output is correct
35 Correct 3 ms 8284 KB Output is correct
36 Correct 3 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 3 ms 8284 KB Output is correct
39 Correct 3 ms 8284 KB Output is correct
40 Correct 4 ms 8284 KB Output is correct
41 Correct 6 ms 8284 KB Output is correct
42 Correct 3 ms 8288 KB Output is correct
43 Correct 3 ms 8304 KB Output is correct
44 Correct 3 ms 8284 KB Output is correct
45 Correct 3 ms 8284 KB Output is correct
46 Correct 3 ms 8284 KB Output is correct
47 Correct 3 ms 8284 KB Output is correct
48 Correct 3 ms 8284 KB Output is correct
49 Correct 4 ms 8092 KB Output is correct
50 Correct 4 ms 8284 KB Output is correct
51 Correct 4 ms 8284 KB Output is correct
52 Correct 3 ms 8304 KB Output is correct
53 Correct 3 ms 8284 KB Output is correct
54 Correct 4 ms 8284 KB Output is correct
55 Correct 4 ms 8284 KB Output is correct
56 Correct 3 ms 8284 KB Output is correct
57 Correct 3 ms 8284 KB Output is correct
58 Correct 3 ms 8116 KB Output is correct
59 Correct 3 ms 8240 KB Output is correct
60 Correct 4 ms 8284 KB Output is correct
61 Correct 3 ms 8304 KB Output is correct
62 Correct 4 ms 8280 KB Output is correct
63 Correct 4 ms 8540 KB Output is correct
64 Correct 4 ms 8180 KB Output is correct
65 Correct 5 ms 8284 KB Output is correct
66 Correct 4 ms 8284 KB Output is correct
67 Correct 4 ms 8540 KB Output is correct
68 Correct 4 ms 8280 KB Output is correct
69 Correct 5 ms 8540 KB Output is correct
70 Correct 4 ms 8392 KB Output is correct
71 Correct 4 ms 8284 KB Output is correct
72 Correct 5 ms 8540 KB Output is correct
73 Correct 5 ms 8540 KB Output is correct
74 Correct 5 ms 8540 KB Output is correct
75 Correct 5 ms 8464 KB Output is correct
76 Correct 5 ms 8284 KB Output is correct
77 Correct 4 ms 8500 KB Output is correct
78 Correct 4 ms 8540 KB Output is correct
79 Correct 4 ms 8284 KB Output is correct
80 Correct 5 ms 8540 KB Output is correct
81 Correct 4 ms 8312 KB Output is correct
82 Correct 6 ms 8540 KB Output is correct
83 Correct 5 ms 8536 KB Output is correct
84 Correct 4 ms 8540 KB Output is correct
85 Correct 5 ms 8476 KB Output is correct
86 Correct 5 ms 8404 KB Output is correct
87 Correct 5 ms 8280 KB Output is correct
88 Correct 104 ms 23764 KB Output is correct
89 Correct 111 ms 23724 KB Output is correct
90 Correct 91 ms 23632 KB Output is correct
91 Correct 46 ms 22100 KB Output is correct
92 Correct 44 ms 22100 KB Output is correct
93 Correct 54 ms 15788 KB Output is correct
94 Correct 54 ms 15696 KB Output is correct
95 Correct 156 ms 24688 KB Output is correct
96 Correct 149 ms 24512 KB Output is correct
97 Correct 155 ms 22996 KB Output is correct
98 Correct 153 ms 23056 KB Output is correct
99 Correct 71 ms 22008 KB Output is correct
100 Correct 70 ms 22128 KB Output is correct
101 Correct 42 ms 22044 KB Output is correct
102 Correct 45 ms 22096 KB Output is correct
103 Correct 43 ms 15696 KB Output is correct
104 Correct 45 ms 15700 KB Output is correct
105 Correct 155 ms 24644 KB Output is correct
106 Correct 171 ms 24576 KB Output is correct
107 Correct 144 ms 29176 KB Output is correct
108 Correct 139 ms 29436 KB Output is correct
109 Correct 75 ms 23164 KB Output is correct
110 Correct 76 ms 23196 KB Output is correct
111 Correct 92 ms 20460 KB Output is correct
112 Correct 93 ms 20440 KB Output is correct