Submission #991253

#TimeUsernameProblemLanguageResultExecution timeMemory
991253VMaksimoski008Drivers (BOI24_drivers)C++17
100 / 100
237 ms15104 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; struct DSU { int n, comp; vector<int> par, size; void config(int _n) { n = _n + 1; comp = _n; par.resize(n+1); size.resize(n+1, 1); for(int i=1; i<=n; i++) par[i] = i; } int get(int u) { if(u == par[u]) return u; return par[u] = get(par[u]); } bool uni(int u, int v) { u = get(u), v = get(v); if(u == v) return false; if(size[u] < size[v]) swap(u, v); size[u] += size[v]; par[v] = u; comp--; return true; } int getComp() { return comp; } int getSize(int u) { return size[get(u)]; } bool sameSet(int u, int v) { return get(u) == get(v); } }; struct Edge { int a, b, w; bool operator<(Edge &e) { return w < e.w; } }; struct Query { int a, b, p, id; bool operator<(Query &q) { return p < q.p; } }; int32_t main() { int n, m, q; cin >> n >> m >> q; vector<Edge> edges(m); for(Edge &e : edges) cin >> e.a >> e.b >> e.w; sort(all(edges)); vector<Query> qus(q); for(int i=0; i<q; i++) { cin >> qus[i].a >> qus[i].b >> qus[i].p; qus[i].id = i; } sort(all(qus)); vector<bool> ans(q); DSU dsu; dsu.config(n); int ptr = 0; for(Query &Q : qus) { while(ptr < m && edges[ptr].w <= Q.p) dsu.uni(edges[ptr].a, edges[ptr].b), ptr++; ans[Q.id] = dsu.sameSet(Q.a, Q.b); } for(int i=0; i<q; i++) cout << (ans[i] ? "TAIP" : "NE") << '\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...