Submission #1103001

# Submission time Handle Problem Language Result Execution time Memory
1103001 2024-10-19T10:39:32 Z THXuan Drivers (BOI24_drivers) C++14
100 / 100
128 ms 25164 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
using namespace std;
typedef long long ll;

ll link[200005];
ll sz[200005];

ll find(int x) {
	while (x != link[x]) x = link[x];
	return x;
}

void unite(int a, int b) {
	a = find(a);
	b = find(b);
	if (a != b) {
		if (sz[a] < sz[b]) swap(a, b);
		sz[a] += sz[b];
		link[b] = a;
	}
}

void solve()
{
	int n, m, u; cin >> n >> m >> u;
	for (int i = 1; i <= n; i++) {
		link[i] = i; sz[i] = 1;
	}
	vector<pair<ll, pair<int, int>>>edges(m);
	vector<pair<pair<ll, int>, pair<int, int>>>q(u);
	vector<string>ans(u);
	for (int i = 0; i < m; i++) {
		cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;
	}
	for (int i = 0; i < u; i++) {
		cin >> q[i].second.first >> q[i].second.second >> q[i].first.first; q[i].first.second = i;
	}
	sort(edges.begin(), edges.end());
	sort(q.begin(), q.end());
	int j = 0;
	for (int i = 0; i < u; i++) {
		while (j < m && edges[j].first <= q[i].first.first) {
			unite(edges[j].second.first, edges[j].second.second);
			++j;
		}
		if (find(q[i].second.first) == find(q[i].second.second)) {
			ans[q[i].first.second] = "TAIP";
		}
		else ans[q[i].first.second] = "NE";
	}
	for (int i = 0; i < u; i++) {
		cout << ans[i] << "\n";
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;// cin>>t;
	while (t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 58 ms 14220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 2 ms 2556 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 3 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 3 ms 2896 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2560 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 6 ms 3152 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 5 ms 3152 KB Output is correct
25 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 58 ms 14220 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 2 ms 2388 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2640 KB Output is correct
11 Correct 3 ms 2896 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2640 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 58 ms 14220 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 2556 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 3 ms 2896 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2560 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 6 ms 3152 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 5 ms 3152 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
31 Correct 1 ms 2552 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 2 ms 2388 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 3 ms 2640 KB Output is correct
36 Correct 3 ms 2896 KB Output is correct
37 Correct 1 ms 2388 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2640 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 58 ms 14220 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 2556 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 3 ms 2896 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2560 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 6 ms 3152 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 5 ms 3152 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
31 Correct 1 ms 2552 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 2 ms 2388 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 3 ms 2640 KB Output is correct
36 Correct 3 ms 2896 KB Output is correct
37 Correct 1 ms 2388 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2640 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 128 ms 18248 KB Output is correct
42 Correct 9 ms 3924 KB Output is correct
43 Correct 10 ms 3820 KB Output is correct
44 Correct 15 ms 3924 KB Output is correct
45 Correct 12 ms 4180 KB Output is correct
46 Correct 8 ms 3668 KB Output is correct
47 Correct 88 ms 17996 KB Output is correct
48 Correct 10 ms 4184 KB Output is correct
49 Correct 92 ms 25164 KB Output is correct