Submission #1304386

#TimeUsernameProblemLanguageResultExecution timeMemory
1304386_TemirhanDrivers (BOI24_drivers)C++20
10 / 100
93 ms24808 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #if defined(__GNUC__) || defined(__clang__) #pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector") #pragma GCC target("avx2,fma,tune=native") #pragma clang loop vectorize(enable) #pragma clang loop interleave(enable) #endif #define int long long #define sz(x) (int)x.size() #define F first #define S second #define pb push_back #define nl '\n' #define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int, int> pii; void file( string s = "" ) { if( s.empty() ) return; freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int N = 2e5 + 2; const int N1 = 1e6 + 2; const int inf = 1e9 + 2; const int INF = 1e18 + 2; const int mod = 1e9 + 7; int T = 1, n, m, q, p[N], sz[N], bl[N], d[N], us[N]; vector< pii > g[N]; vector< array<int, 3> > qr[N]; string ans[N]; int root( int v ) { return v == p[v] ? v : p[v] = root(p[v]); } int merge( int u, int v ) { u = root(u); v = root(v); if( u == v ) return 0; if( sz[u] < sz[v] ) swap(u, v); p[v] = u; sz[u] += sz[v]; return 1; } void calc( int v, int pr ) { sz[v] = 1; d[v] = inf; for( auto [to, w]: g[v] ) if( to != pr && !bl[to] ) { calc(to, v); sz[v] += sz[to]; } } int cntr( int v, int pr, int cnt ) { for( auto [to, w]: g[v] ) if( to != pr && !bl[to] && sz[to] > cnt / 2 ) return cntr(to, v, cnt); return v; } void find_ans( int v, int pr ) { for( auto [u, w, id]: qr[v] ) if( sz(ans[id]) == 0 ) ans[id] = (max(d[u], d[v]) <= w ? "TAIP" : "NE"); for( auto [to, w]: g[v] ) if( to != pr && !bl[to] ) find_ans(to, v); } void SOLVE( int v ) { calc(v, 0); int c = cntr(v, 0, sz[v]); priority_queue< pii > q; q.push({0, c}); d[c] = 0; while( !q.empty() ) { auto [dist, v] = q.top(); q.pop(); if( -dist > d[v] ) continue; for( auto [to, w]: g[v] ) if( !bl[to] && d[to] > max(d[v], w) ) { d[to] = max(d[v], w); q.push({-d[to], to}); } } find_ans(c, 0); bl[c] = 1; for( auto [to, w]: g[c] ) if( !bl[to] ) SOLVE(to); } void solve() { cin >>n >>m >>q; for( int i = 1; i <= n; ++i ) p[i] = i, sz[i] = 1, d[i] = inf; vector< array<int, 3> > vec; for( int i = 1, u, v, w; i <= m; ++i ) { cin >>u >>v >>w; vec.pb({w, u, v}); } sort(vec.begin(), vec.end()); for( auto [w, u, v]: vec ) if( merge(u, v) ) { g[u].pb({v, w}); g[v].pb({u, w}); } for( int i = 1, u, v, w; i <= q; ++i ) { ans[i] = ""; cin >>u >>v >>w; qr[u].pb({v, w, i}); qr[v].pb({u, w, i}); } for( int u = 1; u <= n; ++u ) if( !bl[u] ) { SOLVE(u); calc(u, 0); } for( int i = 1; i <= q; ++i ) cout <<ans[i] <<nl; } signed main() { file(""); ios_base::sync_with_stdio(false); cin.tie(nullptr); // cin >>T; while( T-- ) solve(); }

Compilation message (stderr)

Main.cpp: In function 'void file(std::string)':
Main.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...