// subtask 1
#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(ll x) {
while (x != link[x]) x = link[x];
return x;
}
void unite(ll a, ll b) {
a = find(a);
b = find(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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
427 ms |
14216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2556 KB |
Output is correct |
6 |
Correct |
1 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2600 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
3 ms |
2528 KB |
Output is correct |
11 |
Correct |
4 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
3 ms |
2900 KB |
Output is correct |
15 |
Correct |
1 ms |
2556 KB |
Output is correct |
16 |
Correct |
1 ms |
2388 KB |
Output is correct |
17 |
Correct |
1 ms |
2388 KB |
Output is correct |
18 |
Correct |
1 ms |
2388 KB |
Output is correct |
19 |
Correct |
6 ms |
3412 KB |
Output is correct |
20 |
Correct |
1 ms |
2388 KB |
Output is correct |
21 |
Correct |
1 ms |
2388 KB |
Output is correct |
22 |
Correct |
1 ms |
2388 KB |
Output is correct |
23 |
Correct |
1 ms |
2388 KB |
Output is correct |
24 |
Correct |
5 ms |
3412 KB |
Output is correct |
25 |
Correct |
1 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
427 ms |
14216 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
3 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
5 ms |
2644 KB |
Output is correct |
11 |
Correct |
3 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
2388 KB |
Output is correct |
14 |
Correct |
1 ms |
2388 KB |
Output is correct |
15 |
Correct |
1 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
427 ms |
14216 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2388 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2556 KB |
Output is correct |
11 |
Correct |
1 ms |
2388 KB |
Output is correct |
12 |
Correct |
1 ms |
2600 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2388 KB |
Output is correct |
15 |
Correct |
3 ms |
2528 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
4 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2900 KB |
Output is correct |
20 |
Correct |
1 ms |
2556 KB |
Output is correct |
21 |
Correct |
1 ms |
2388 KB |
Output is correct |
22 |
Correct |
1 ms |
2388 KB |
Output is correct |
23 |
Correct |
1 ms |
2388 KB |
Output is correct |
24 |
Correct |
6 ms |
3412 KB |
Output is correct |
25 |
Correct |
1 ms |
2388 KB |
Output is correct |
26 |
Correct |
1 ms |
2388 KB |
Output is correct |
27 |
Correct |
1 ms |
2388 KB |
Output is correct |
28 |
Correct |
1 ms |
2388 KB |
Output is correct |
29 |
Correct |
5 ms |
3412 KB |
Output is correct |
30 |
Correct |
1 ms |
2388 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
3 ms |
2644 KB |
Output is correct |
35 |
Correct |
5 ms |
2644 KB |
Output is correct |
36 |
Correct |
3 ms |
2900 KB |
Output is correct |
37 |
Correct |
1 ms |
2388 KB |
Output is correct |
38 |
Correct |
1 ms |
2388 KB |
Output is correct |
39 |
Correct |
1 ms |
2388 KB |
Output is correct |
40 |
Correct |
1 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
427 ms |
14216 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2388 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2556 KB |
Output is correct |
11 |
Correct |
1 ms |
2388 KB |
Output is correct |
12 |
Correct |
1 ms |
2600 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2388 KB |
Output is correct |
15 |
Correct |
3 ms |
2528 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
4 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2900 KB |
Output is correct |
20 |
Correct |
1 ms |
2556 KB |
Output is correct |
21 |
Correct |
1 ms |
2388 KB |
Output is correct |
22 |
Correct |
1 ms |
2388 KB |
Output is correct |
23 |
Correct |
1 ms |
2388 KB |
Output is correct |
24 |
Correct |
6 ms |
3412 KB |
Output is correct |
25 |
Correct |
1 ms |
2388 KB |
Output is correct |
26 |
Correct |
1 ms |
2388 KB |
Output is correct |
27 |
Correct |
1 ms |
2388 KB |
Output is correct |
28 |
Correct |
1 ms |
2388 KB |
Output is correct |
29 |
Correct |
5 ms |
3412 KB |
Output is correct |
30 |
Correct |
1 ms |
2388 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
3 ms |
2644 KB |
Output is correct |
35 |
Correct |
5 ms |
2644 KB |
Output is correct |
36 |
Correct |
3 ms |
2900 KB |
Output is correct |
37 |
Correct |
1 ms |
2388 KB |
Output is correct |
38 |
Correct |
1 ms |
2388 KB |
Output is correct |
39 |
Correct |
1 ms |
2388 KB |
Output is correct |
40 |
Correct |
1 ms |
2388 KB |
Output is correct |
41 |
Execution timed out |
2032 ms |
24612 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |