#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <bit>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <time.h>
#include <random>
#include <inttypes.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3,Ofast")
#define EPS 1e-9
#define PI acos(-1)
#define MAXN 200'005
#define MOD 1'000'000'007
#define INF 1'000'000'000'000
#define ll int64_t
#define int int32_t
#define short int16_t
#define si(n) if(scanf("%d", &n))
#define sl(n) scanf("%ld", &n);
#define sc(n) scanf("%c", &n);
#define sf(n) scanf("%f", &n);
#define slf(n) scanf("%lf", &n);
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define dbg(x) std::cerr << #x << ": " << x << std::endl;
typedef std::set<int> si;
typedef std::set<ll> sll;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<std::vector<int>> dvi;
typedef std::vector<std::vector<ll>> dvll;
typedef std::unordered_map<int , int> mi;
typedef std::unordered_map<ll , ll> mll;
ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b) * b;}
int N, M, Q;
int *par, *size;
std::tuple<int, int, int> queriesIndex[MAXN];
std::vector<std::tuple<int, int, int>> edges, queries;
std::map<std::tuple<int, int, int>, std::string> answerMap;
//Union Psajimo
void DSU() {
for(int i = 1; i <= N; ++i) {
par[i] = i;
size[i] = 1;
}
}
int find(int a) {
if(a == par[a]) return a;
return par[a] = find(par[a]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if(size[a] < size[b]) std::swap(a, b);
par[b] = a;
size[a] += size[b];
}
bool same(int a, int b) {
return find(a) == find(b);
}
signed main()
{
si(N) si(M) si(Q)
par = new int[N+1];
size = new int[N+1];
DSU();
for(int i = 0; i < M; ++i) {
int u, v, w;
si(u) si(v) si(w)
edges.pb({w, u, v});
}
for(int i = 0; i < Q; ++i) {
int a, b, p;
si(a) si(b) si(p)
queriesIndex[i] = {p, a, b};
queries.pb({p, a, b});
}
std::sort(all(edges));
std::sort(all(queries));
for(int i = 0; i < Q; ++i) {
int a, b, p, indx = 0, u, v, w;
std::tie(p, a, b) = queries[i];
std::tie(w, u, v) = edges[indx++];
while(w <= p && indx < M) {
if(!same(u, v)) unite(u, v);
std::tie(w, u, v) = edges[indx++];
}
if(same(a, b)) answerMap[{p, a, b}] = "TAIP";
else answerMap[{p, a, b}] = "NE";
}
for(int i = 0; i < Q; ++i) {
std::cout<<answerMap[queriesIndex[i]]<<"\n";
}
delete[] par;
delete[] size;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |