답안 #1118688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118688 2024-11-26T02:17:37 Z YSH2020 Drivers (BOI24_drivers) C++17
100 / 100
285 ms 18508 KB
#include <bits/stdc++.h>
using namespace std;

int p[200005];

int parent(int n) {
    if (p[n] == n) return n;
    return p[n] = parent(p[n]);
}

void merge(int x, int y) {
    x = parent(x); y = parent(y);
    if (x == y) return;
    p[x] = y;
}

int main() {
    int n, m, u; cin >> n >> m >> u;
    vector <pair<int, pair<int, int>>> edges;
    for (int i = 0; i < m; i++) {
        int x, y, w; cin >> x >> y >> w;
        edges.push_back({w, {x, y}});
    }
    sort(edges.begin(), edges.end());
    for (int i = 1; i <= n; i++) p[i] = i;
    vector <pair<pair<int, int>, pair<int, int>>> query;
    int ans[u];
    for (int i = 0; i < u; i++) {
        int x, y, dist; cin >> x >> y >> dist;
        query.push_back({{dist, i}, {x, y}});
    }
    sort(query.begin(), query.end());
    int idx = 0;
    for (int i = 0; i < u; i++) {
        while (idx < m and edges[idx].first <= query[i].first.first) {
            merge(edges[idx].second.first, edges[idx].second.second);
            idx++;
        }
        if (parent(query[i].second.first) == parent(query[i].second.second)) ans[query[i].first.second] = 1;
        else ans[query[i].first.second] = 0;
    }
    for (int i = 0; i < u; i++) {
        if (ans[i] == 0) cout << "NE" << '\n';
        else cout << "TAIP" << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 352 KB Output is correct
3 Correct 4 ms 608 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 181 ms 9396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 2 ms 352 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 6 ms 460 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 8 ms 752 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 14 ms 1168 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 17 ms 1168 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 352 KB Output is correct
3 Correct 4 ms 608 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 181 ms 9396 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 4 ms 608 KB Output is correct
9 Correct 6 ms 608 KB Output is correct
10 Correct 5 ms 608 KB Output is correct
11 Correct 6 ms 864 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 352 KB Output is correct
3 Correct 4 ms 608 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 181 ms 9396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 2 ms 352 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 352 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 8 ms 752 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 14 ms 1168 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 17 ms 1168 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 352 KB Output is correct
32 Correct 2 ms 352 KB Output is correct
33 Correct 4 ms 608 KB Output is correct
34 Correct 6 ms 608 KB Output is correct
35 Correct 5 ms 608 KB Output is correct
36 Correct 6 ms 864 KB Output is correct
37 Correct 1 ms 616 KB Output is correct
38 Correct 1 ms 352 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 352 KB Output is correct
3 Correct 4 ms 608 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 181 ms 9396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 2 ms 352 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 352 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 8 ms 752 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 14 ms 1168 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 17 ms 1168 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 352 KB Output is correct
32 Correct 2 ms 352 KB Output is correct
33 Correct 4 ms 608 KB Output is correct
34 Correct 6 ms 608 KB Output is correct
35 Correct 5 ms 608 KB Output is correct
36 Correct 6 ms 864 KB Output is correct
37 Correct 1 ms 616 KB Output is correct
38 Correct 1 ms 352 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 285 ms 18508 KB Output is correct
42 Correct 19 ms 1628 KB Output is correct
43 Correct 18 ms 1300 KB Output is correct
44 Correct 30 ms 1872 KB Output is correct
45 Correct 24 ms 1872 KB Output is correct
46 Correct 15 ms 1300 KB Output is correct
47 Correct 262 ms 13792 KB Output is correct
48 Correct 21 ms 1872 KB Output is correct
49 Correct 248 ms 18228 KB Output is correct