Submission #1111363

#TimeUsernameProblemLanguageResultExecution timeMemory
1111363siewjhDrivers (BOI24_drivers)C++17
100 / 100
112 ms8272 KiB
#include <bits/stdc++.h> using namespace std; typedef tuple<int, int, int> i3; typedef tuple<int, int, int, int> i4; const int MAXN = 200005; int par[MAXN], rnk[MAXN]; int root(int x){ if (par[x] == -1) return x; else return par[x] = root(par[x]); } void join(int a, int b){ int ra = root(a), rb = root(b); if (ra == rb) return; if (rnk[ra] > rnk[rb]) swap(ra, rb); par[ra] = rb; if (rnk[ra] == rnk[rb]) rnk[rb]++; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nodes, edges, queries; cin >> nodes >> edges >> queries; memset(par, -1, sizeof(par)); vector<i3> ev(edges); vector<i4> pv(queries); for (int i = 0; i < edges; i++){ int a, b, c; cin >> a >> b >> c; ev[i] = {c, a, b}; } sort(ev.begin(), ev.end()); for (int i = 0; i < queries; i++){ int a, b, p; cin >> a >> b >> p; pv[i] = {p, a, b, i}; } sort(pv.begin(), pv.end()); vector<bool> ans(queries); int eid = 0; for (auto [p, a, b, i] : pv){ for (; eid != edges && get<0>(ev[eid]) <= p; eid++){ int ea, eb, ec; tie(ec, ea, eb) = ev[eid]; join(ea, eb); } ans[i] = (root(a) == root(b)); } for (bool b : ans) cout << (b ? "TAIP" : "NE") << '\n'; }
#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...