#include<bits/stdc++.h>
using namespace std;
#define NAME "DRIVERS"
#define nl '\n'
#define allofa(x,sz) x,x+sz+1
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,val) memset(x,val,sizeof(x))
#define couf(x) cout << fixed << setprecision(x)
template<class T> T Abs(T &x) {return (x>=0 ? x : -x);};
template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;};
typedef long long ll;
typedef pair<ll,int> pli;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e15;
const int INF = (int)1e9;
const int MAXN = (int)2e5+5;
vector<pli> graph[MAXN];
set<int> isSub1;
int n,m,q;
void ccps() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen(NAME".inp","r")) {
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
}
namespace subtask1 {
const int N = (int)1e4+5;
ll dist[N][N];
bool check() {
return (int)isSub1.size()==1 and 1<=n and n<=1e4 and 1<=m and m<=1e4;
}
void bfs(int src) {
fill(allofa(dist[src],n+1),INF);
queue<int> q;
q.push(src);
dist[src][src]=0;
while(!q.empty()) {
int u = q.front();q.pop();
for (pli x : graph[u]) {
int v = x.second;
if(dist[src][v]==INF) {
dist[src][v]=dist[src][u]+1;
q.push(v);
}
}
}
}
void sol() {
int w = *isSub1.begin();
for (int u = 1; u<=n; u++) bfs(u);
for (int u = 1; u<=n; u++) {
for (int v = 1; v<=n; v++) {
if(dist[u][v]==INF) continue;
else dist[u][v]*=w;
}
}
while(q--) {
int x,y,t; cin >> x >> y >> t;
if(dist[x][y]>t) cout << "NO" << nl;
else cout << "YES" << nl;
}
}
}
signed main() {
ccps();
cin >> n >> m >> q;
for (int i = 1; i<=m; i++) {
int u,v; ll w; cin >> u >> v >> w;
graph[u].push_back({w,v});
graph[v].push_back({w,u});
isSub1.insert(w);
}
if(subtask1::check()) subtask1::sol();
else cout << "NO";
}
Compilation message (stderr)
Main.cpp: In function 'void ccps()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(NAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen(NAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |