#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// using namespace __gnu_pbds;
typedef long long ll;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpi vector<pair<int,int>>
#define rep(ii,st, n) for(int ii=st; ii<n; ii++)
#define gp " "
//bit_manupulation
#define checkbit(x,n) (x&(1LL<<n))
#define setbit(x,n) (x=(x|(1LL<<n)))
#define resetbit(x,n) (x=(x&(~(1LL<<n))))
#define pow2(i) (1LL<<i)
#define bitcnt(x) ((sizeof(x) <= sizeof(int)) ? (32 - __builtin_clz(x)) : (64 - __builtin_clzll(x)))
#define DEBG
#define debug(n)
#define debugc(a)
#define debugcc(a)
#ifdef DEBG
#define debug(n) cout<<__LINE__<<gp<<#n<<gp<<n<<endl;
#define debugc(a) cout<<__LINE__<<gp<<#a<<gp<<'['<<gp;for(auto el:a){cout<<el<<gp;}cout<<']'<<endl;
#define debugcc(a) cout<<__LINE__<<gp<<#a<<gp<<'['<<gp;for(auto el:a){cout<<'{'<<gp<<el.ff<<','<<el.ss<<gp<<'}'<<gp;}cout<<']'<<endl;
#endif
#define fastcin() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define All(a) a.begin(),a.end()
template<typename T> void get_vector(T&a){for(auto&e:a)cin>>e;}
template<typename T> void put_vector(T a){for(auto e:a)cout<<e<<" ";cout<<endl;}
const ll INF = 2e18;
const ll inf = INT_MAX;
const ll M = 1e9 + 7;
const ll N = 1e4+7;
const ll modinvof2 = 500000004;
//==============================CODE STARTS HERE==============================//
// const int N = 5e5+7;
int n,m,u;
vector<vector<pair<int,int>>>g;
vector<bool>visited;
// vector<vector<int>>connected_components;
vector<int>current_cc;
map<int,int>mp;
multiset<int>ms;
bool fl = false;
int ans = -1;
void dfs(int vertex){
if(visited[vertex]){
return;
}
visited[vertex] = true;
current_cc.push_back(vertex);
for(auto child: g[vertex]){
dfs(child.ff);
}
}
void dfs2(int vertex, int ex){
if(fl){
return;
}
if(vertex == ex){
fl = true;
return;
}
if(visited[vertex]){
return;
}
visited[vertex] = true;
// current_cc.push_back(vertex);
int wei = 0;
for(auto child: g[vertex]){
int el = child.ff;
int w = child.ss;
ms.insert(w);
dfs2(el,ex);
if(fl){
ans = (*(--ms.end()));
return;
}
ms.erase(ms.find(w));
}
}
void preprocessing(){
}
void solve(int testcases){
cin>>n>>m>>u;
int t = 0;
g.resize(n+7);
visited.resize(n+7);
for(int i = 0; i<m; i++){
int a,b,c;
cin>>a>>b>>c;
g[a].push_back({b,c});
g[b].push_back({a,c});
// t = c;
}
int lvl = 1;
for(int i = 1; i<=n; i++){
if(visited[i]){
continue;
}
dfs(i);
// connected_components.push_back(current_cc);
for(auto& el: current_cc){
mp[el] = lvl;
}
lvl++;
current_cc.clear();
}
for(int i = 0; i<n+7; i++){
visited[i] = 0;
}
while(u--){
int x,y,p;
cin>>x>>y>>p;
if(mp[x]!=mp[y]){
cout<<"NE\n";
continue;
}
dfs2(x,y);
if(ans>p){
cout<<"NE\n";
ans = -1;
continue;
}
cout<<"TAIP\n";
ans = -1;
}
}
int32_t main(){
fastcin();
int t=1;
// cin>>t;
preprocessing();
rep(i,1,t+1){
solve(i);
}
return 0;
}
Compilation message (stderr)
Main.cpp:37: warning: "debug" redefined
37 | #define debug(n) cout<<__LINE__<<gp<<#n<<gp<<n<<endl;
|
Main.cpp:33: note: this is the location of the previous definition
33 | #define debug(n)
|
Main.cpp:38: warning: "debugc" redefined
38 | #define debugc(a) cout<<__LINE__<<gp<<#a<<gp<<'['<<gp;for(auto el:a){cout<<el<<gp;}cout<<']'<<endl;
|
Main.cpp:34: note: this is the location of the previous definition
34 | #define debugc(a)
|
Main.cpp:39: warning: "debugcc" redefined
39 | #define debugcc(a) cout<<__LINE__<<gp<<#a<<gp<<'['<<gp;for(auto el:a){cout<<'{'<<gp<<el.ff<<','<<el.ss<<gp<<'}'<<gp;}cout<<']'<<endl;
|
Main.cpp:35: note: this is the location of the previous definition
35 | #define debugcc(a)
|| # | 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... |