#include<bits/stdc++.h>
using namespace std;
#define int long long
using ii = pair<int, int>;
vector<vector<ii>> adj;
int n, m, u;
/* observation: abs(dist(a, x) - dist(b, x)) <= dist(a, b) <= dist(a, x) + dist(b, x)
* in fact, only the left half is useful.
* The answer is YES, iff we can find some abs(dist(a, x) - dist(b, x)) <= p (the query value).
*/
bool dfs(int u, int t, int p, vector<bool>& visited) {
if (visited[u]) return false;
if (u == t) return true;
visited[u] = true;
for (auto [v, w] : adj[u]) {
if (w > p) continue;
bool r = dfs(v, t, p, visited);
if (r) return true;
}
return false;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m >> u;
// all nodes are 1-indexed.
adj = vector<vector<ii>>(n+1, vector<ii>());
for (int i = 0; i < m; i++) {
int a, b, t; cin >> a >> b >> t;
adj[a].push_back({b, t});
adj[b].push_back({a, t});
}
// queries
while (u--) {
int a, b, p; cin >> a >> b >> p;
vector<bool> visited(n+1, false);
auto ok = dfs(a, b, p, visited);
if (ok) {
cout << "TAIP\n";
}
else {
cout << "NE\n";
}
}
}
Compilation message
Main.cpp: In function 'bool dfs(long long int, long long int, long long int, std::vector<bool>&)':
Main.cpp:21:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
21 | for (auto [v, w] : adj[u]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
1596 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
12 ms |
592 KB |
Output is correct |
11 |
Correct |
23 ms |
592 KB |
Output is correct |
12 |
Correct |
24 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
3 ms |
760 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
473 ms |
1104 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
5 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
352 ms |
1468 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
1596 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
1596 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
1596 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |