Submission #1103001

#TimeUsernameProblemLanguageResultExecution timeMemory
1103001THXuanDrivers (BOI24_drivers)C++14
100 / 100
128 ms25164 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 using namespace std; typedef long long ll; ll link[200005]; ll sz[200005]; ll find(int x) { while (x != link[x]) x = link[x]; return x; } void unite(int a, int b) { a = find(a); b = find(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); sz[a] += sz[b]; link[b] = a; } } void solve() { int n, m, u; cin >> n >> m >> u; for (int i = 1; i <= n; i++) { link[i] = i; sz[i] = 1; } vector<pair<ll, pair<int, int>>>edges(m); vector<pair<pair<ll, int>, pair<int, int>>>q(u); vector<string>ans(u); for (int i = 0; i < m; i++) { cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first; } for (int i = 0; i < u; i++) { cin >> q[i].second.first >> q[i].second.second >> q[i].first.first; q[i].first.second = i; } sort(edges.begin(), edges.end()); sort(q.begin(), q.end()); int j = 0; for (int i = 0; i < u; i++) { while (j < m && edges[j].first <= q[i].first.first) { unite(edges[j].second.first, edges[j].second.second); ++j; } if (find(q[i].second.first) == find(q[i].second.second)) { ans[q[i].first.second] = "TAIP"; } else ans[q[i].first.second] = "NE"; } for (int i = 0; i < u; i++) { cout << ans[i] << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin>>t; while (t--) solve(); 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...