답안 #1111965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111965 2024-11-13T12:56:49 Z gohchingjayk Drivers (BOI24_drivers) C++17
100 / 100
261 ms 14376 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = int64_t;

struct Road {
    int from;
    int to;
    int length;
};

struct Query {
    int from;
    int to;
    int length;
    int original;
};

Road roads[200000];
Query queries[200000];
int parent[200001];
bool result[200000];

int findparent(int i) {
    return parent[i] = (i == parent[i] ? i : findparent(parent[i]));
}

int main() {
    int n_cities, n_roads, n_queries;
    cin >> n_cities >> n_roads >> n_queries;

    for (int i = 0; i < 200001; ++i) parent[i] = i;

    for (int i = 0; i < n_roads; ++i) {
        int from, to, length;
        cin >> from >> to >> length;
        roads[i] = Road{.from = from, .to = to, .length = length};
    }

    for (int i = 0; i < n_queries; ++i) {
        int from, to, length;
        cin >> from >> to >> length;
        queries[i] = Query{.from = from, .to = to, .length = length, .original = i};
    }

    sort(roads, roads + n_roads, [&](const Road &a, const Road &b){ return a.length < b.length; });
    sort(queries, queries + n_queries, [&](const Query &a, const Query &b){ return a.length < b.length; });

    int curr_road = 0;
    for (int i = 0; i < n_queries; ++i) {
        Query query = queries[i];

        for (; curr_road < n_roads; ++curr_road) {
            if (roads[curr_road].length > query.length) break;
            int f = roads[curr_road].from;
            int t = roads[curr_road].to;
            parent[findparent(f)] = findparent(t);
        }

        result[query.original] = findparent(query.from) == findparent(query.to);
    }

    for (int i = 0; i < n_queries; ++i) {
        cout << (result[i] ? "TAIP" : "NE");
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 110 ms 7780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4576 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 3 ms 4432 KB Output is correct
8 Correct 3 ms 4432 KB Output is correct
9 Correct 3 ms 4432 KB Output is correct
10 Correct 3 ms 4588 KB Output is correct
11 Correct 4 ms 4432 KB Output is correct
12 Correct 8 ms 4568 KB Output is correct
13 Correct 3 ms 4432 KB Output is correct
14 Correct 6 ms 4592 KB Output is correct
15 Correct 2 ms 4600 KB Output is correct
16 Correct 2 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4432 KB Output is correct
19 Correct 11 ms 4688 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 2 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 10 ms 4688 KB Output is correct
25 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 110 ms 7780 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 4 ms 4600 KB Output is correct
9 Correct 4 ms 4432 KB Output is correct
10 Correct 5 ms 4564 KB Output is correct
11 Correct 5 ms 4432 KB Output is correct
12 Correct 2 ms 4600 KB Output is correct
13 Correct 1 ms 4548 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 110 ms 7780 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4576 KB Output is correct
10 Correct 2 ms 4560 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 3 ms 4432 KB Output is correct
13 Correct 3 ms 4432 KB Output is correct
14 Correct 3 ms 4432 KB Output is correct
15 Correct 3 ms 4588 KB Output is correct
16 Correct 4 ms 4432 KB Output is correct
17 Correct 8 ms 4568 KB Output is correct
18 Correct 3 ms 4432 KB Output is correct
19 Correct 6 ms 4592 KB Output is correct
20 Correct 2 ms 4600 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 11 ms 4688 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 2 ms 4432 KB Output is correct
28 Correct 2 ms 4432 KB Output is correct
29 Correct 10 ms 4688 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 3 ms 4560 KB Output is correct
33 Correct 4 ms 4600 KB Output is correct
34 Correct 4 ms 4432 KB Output is correct
35 Correct 5 ms 4564 KB Output is correct
36 Correct 5 ms 4432 KB Output is correct
37 Correct 2 ms 4600 KB Output is correct
38 Correct 1 ms 4548 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 110 ms 7780 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4576 KB Output is correct
10 Correct 2 ms 4560 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 3 ms 4432 KB Output is correct
13 Correct 3 ms 4432 KB Output is correct
14 Correct 3 ms 4432 KB Output is correct
15 Correct 3 ms 4588 KB Output is correct
16 Correct 4 ms 4432 KB Output is correct
17 Correct 8 ms 4568 KB Output is correct
18 Correct 3 ms 4432 KB Output is correct
19 Correct 6 ms 4592 KB Output is correct
20 Correct 2 ms 4600 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 11 ms 4688 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 2 ms 4432 KB Output is correct
28 Correct 2 ms 4432 KB Output is correct
29 Correct 10 ms 4688 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 3 ms 4560 KB Output is correct
33 Correct 4 ms 4600 KB Output is correct
34 Correct 4 ms 4432 KB Output is correct
35 Correct 5 ms 4564 KB Output is correct
36 Correct 5 ms 4432 KB Output is correct
37 Correct 2 ms 4600 KB Output is correct
38 Correct 1 ms 4548 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 261 ms 14376 KB Output is correct
42 Correct 16 ms 6992 KB Output is correct
43 Correct 17 ms 6992 KB Output is correct
44 Correct 26 ms 7132 KB Output is correct
45 Correct 23 ms 7160 KB Output is correct
46 Correct 16 ms 6992 KB Output is correct
47 Correct 198 ms 12144 KB Output is correct
48 Correct 21 ms 6992 KB Output is correct
49 Correct 229 ms 13924 KB Output is correct