#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]);
}
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);
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
77 ms |
3680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
77 ms |
3680 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |