This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, pii> ppp;
#define fi first
#define se second
const int MAXN = 200005;
int p[MAXN];
int get_parent(int x){
if(p[x] == x) return x;
p[x] = get_parent(p[x]);
return p[x];
}
void union_set(int u, int v){
u = get_parent(u);
v = get_parent(v);
if(u==v) return;
p[u] = v;
}
int main(){
cin.tie(0); ios_base::sync_with_stdio(0);
int n, m, u;
cin >> n >> m >> u;
deque<pip> r;
for(int i=0; i<m; i++){
pip tmp;
cin >> tmp.se.fi >> tmp.se.se >> tmp.fi;
r.push_back(tmp);
}
sort(r.begin(), r.end());
deque<ppp> c;
for(int i=0; i<u; i++){
ppp tmp;
cin >> tmp.se.fi >> tmp.se.se >> tmp.fi.fi;
tmp.fi.se = i;
c.push_back(tmp);
}
sort(c.begin(), c.end());
for(int i=1; i<=n; i++){
p[i] = i;
}
vector<bool> ans(u, 0);
for(auto i: c){
while(r.size() && r.front().fi <= i.fi.fi){
union_set(r.front().se.fi, r.front().se.se);
r.pop_front();
}
ans[i.fi.se] = get_parent(i.se.fi) == get_parent(i.se.se);
}
for(auto i: ans){
if(i){
cout << "TAIP\n";
}
else{
cout << "NE\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |