Submission #372518

#TimeUsernameProblemLanguageResultExecution timeMemory
372518gustasonTrucks (LMIO17_sunkvezimiai)C++11
10 / 100
60 ms1260 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int maxN = 2e5 + 5; int parent[maxN], sz[maxN], mx[maxN]; int find(int v) { if (v == parent[v]) return v; return parent[v] = find(parent[v]); } void unite(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (sz[a] < sz[b]) { swap(a, b); } parent[b] = a; sz[a] += sz[b]; mx[a] = max(mx[a], mx[b]); } bool can(int a, int b, int w) { a = find(a), b = find(b); return a == b && w >= mx[a]; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; for(int i = 0; i <= n; i++) { sz[i] = 1; parent[i] = i; } for(int i = 0; i < m; i++) { int a, b, w; cin >> a >> b >> w; unite(a, b); mx[find(a)] = max(mx[find(a)], w); } while(q--) { int a, b, t; cin >> a >> b >> t; if (can(a, b, t)) { cout << "TAIP\n"; } else { cout << "NE\n"; } } // for(int i = 0; i <= n; i++) { // cout << mx[i] << " " << parent[i] << "\n"; // } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...