#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 2e5 + 5;
int parent[maxN], sz[maxN], mx[maxN];
int find(int v) {
if (v == parent[v])
return v;
return parent[v] = find(parent[v]);
}
void unite(int a, int b) {
a = find(a), b = find(b);
if (a == b) return;
if (sz[a] < sz[b]) {
swap(a, b);
}
parent[b] = a;
sz[a] += sz[b];
mx[a] = max(mx[a], mx[b]);
mx[b] = max(mx[a], mx[b]);
}
bool can(int a, int b, int w) {
a = find(a), b = find(b);
return a == b && w > mx[a];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for(int i = 0; i <= n; i++) {
sz[i] = 1;
parent[i] = i;
}
for(int i = 0; i < m; i++) {
int a, b, w;
cin >> a >> b >> w;
unite(a, b);
mx[find(a)] = max(mx[find(a)], w);
mx[find(b)] = max(mx[find(b)], w);
}
while(q--) {
int a, b, t;
cin >> a >> b >> t;
if (can(a, b, t)) {
cout << "TAIP\n";
} else {
cout << "NE\n";
}
}
// for(int i = 0; i <= n; i++) {
// cout << mx[i] << " " << parent[i] << "\n";
// }
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |