#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, pair<int, int>> iii;
typedef pair<int, pair<pair<int, int>, int>> iiii;
typedef pair<int, string> ii;
vector<int> p;
int fin(int a)
{
if (p[a] == a)
return a;
return p[a] = fin(p[a]);
}
void join(int a, int b)
{
a = fin(a);
b = fin(b);
if (a == b) return;
p[a] = b;
}
signed main()
{
int N, M, U, x, y, t;
cin >> N >> M >> U;
for (int i = 0; i < N; i++)
p.push_back(i);
priority_queue<iii, vector<iii>, greater<iii>> pq;
priority_queue<iiii, vector<iiii>, greater<iiii>> query;
for (int i = 0; i < M; i++)
{
cin >> x >> y >> t;
x--, y--;
pq.push({t, {x, y}});
}
for (int i = 0; i < U; i++)
{
cin >> x >> y >> t;
x--, y--;
query.push({t, {{x, y}, i}});
}
priority_queue<ii, vector<ii>, greater<ii>> ans;
while (!query.empty())
{
auto i = query.top();
query.pop();
while (!pq.empty() && pq.top().first <= i.first)
{
auto j = pq.top();
pq.pop();
join(j.second.first, j.second.second);
}
if (fin(i.second.first.first) == fin(i.second.first.second))
ans.push({i.second.second, "TAIP\n"});
else
ans.push({i.second.second, "NE\n"});
}
while (!ans.empty())
{
cout << ans.top().second;
ans.pop();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
169 ms |
25316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 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 |
764 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
4 ms |
592 KB |
Output is correct |
11 |
Correct |
6 ms |
592 KB |
Output is correct |
12 |
Correct |
6 ms |
788 KB |
Output is correct |
13 |
Correct |
3 ms |
592 KB |
Output is correct |
14 |
Correct |
8 ms |
1160 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 |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
15 ms |
1864 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
14 ms |
1864 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
169 ms |
25316 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
788 KB |
Output is correct |
11 |
Correct |
6 ms |
1396 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
169 ms |
25316 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
3 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
6 ms |
592 KB |
Output is correct |
17 |
Correct |
6 ms |
788 KB |
Output is correct |
18 |
Correct |
3 ms |
592 KB |
Output is correct |
19 |
Correct |
8 ms |
1160 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
15 ms |
1864 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
14 ms |
1864 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
592 KB |
Output is correct |
33 |
Correct |
3 ms |
592 KB |
Output is correct |
34 |
Correct |
4 ms |
592 KB |
Output is correct |
35 |
Correct |
6 ms |
788 KB |
Output is correct |
36 |
Correct |
6 ms |
1396 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
169 ms |
25316 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
3 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
6 ms |
592 KB |
Output is correct |
17 |
Correct |
6 ms |
788 KB |
Output is correct |
18 |
Correct |
3 ms |
592 KB |
Output is correct |
19 |
Correct |
8 ms |
1160 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
15 ms |
1864 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
14 ms |
1864 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
592 KB |
Output is correct |
33 |
Correct |
3 ms |
592 KB |
Output is correct |
34 |
Correct |
4 ms |
592 KB |
Output is correct |
35 |
Correct |
6 ms |
788 KB |
Output is correct |
36 |
Correct |
6 ms |
1396 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
360 ms |
33188 KB |
Output is correct |
42 |
Correct |
22 ms |
2248 KB |
Output is correct |
43 |
Correct |
22 ms |
1868 KB |
Output is correct |
44 |
Correct |
30 ms |
1992 KB |
Output is correct |
45 |
Correct |
26 ms |
2496 KB |
Output is correct |
46 |
Correct |
19 ms |
2120 KB |
Output is correct |
47 |
Correct |
242 ms |
22372 KB |
Output is correct |
48 |
Correct |
23 ms |
2528 KB |
Output is correct |
49 |
Correct |
275 ms |
33204 KB |
Output is correct |