제출 #1196278

#제출 시각아이디문제언어결과실행 시간메모리
1196278AldkDrivers (BOI24_drivers)C++20
100 / 100
109 ms20588 KiB
#include<bits/stdc++.h> #define pb push_back #define F first #define S second #define str string #define ll long long #define ull unsigned ll #define ld long double #define pll pair<ll,ll> #define plll pair<ll,pll> #define pllll pair<pll,pll> #define pii pair<int,int> #define vl vector<ll> #define vll vector<pll> #define vlll vector<plll> #define vllll vector<pllll> #define vi vector<int> #define vii vector<pii> #define sz(x) (ll)(x).size() #define fr front() #define tp top() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ins insert #define m_p make_pair #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") using namespace std; const ld pi=acos(-1.0); const ll e5=1e5, e6=1e6, e9=1e9; const ll inf=1e18; const ll mod=998244353; const ll MOD=106710087877475399; const ll N=2e5+10; const ll M=2e5+10; const ld eps=1e-9; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;ll p=bpm(x,y/2,m); if(y%2==0)return p*p%m;else return p*p%m*x%m;} ll bp(ll x,ll y){if(y==0)return 1;ll p=bp(x,y/2); if(y%2==0)return p*p;else return p*p*x;} ll n,m,q,p[N],s[N]; bool ans[N]; ll get(ll v){ if(v==p[v]) return v; return p[v]=get(p[v]); } void mrg(ll a,ll b){ a=get(a), b=get(b); if(a==b) return; if(s[a]<s[b]) swap(a,b); s[a]+=s[b]; p[b]=a; } void solve(){ cin>>n>>m>>q; for(ll i=1;i<=n;i++) p[i]=i, s[i]=1; vlll vt; vllll qr; for(ll i=1;i<=m;i++){ ll a,b,t; cin>>a>>b>>t; vt.pb({t,{a,b}}); } sort(all(vt)); for(ll i=1;i<=q;i++){ ll a,b,t; cin>>a>>b>>t; qr.pb({{t,i},{a,b}}); } sort(all(qr)); ll i=0; for(auto pr:qr){ ll a=pr.S.F, b=pr.S.S, t=pr.F.F, id=pr.F.S; while(i<sz(vt)&&vt[i].F<=t){ mrg(vt[i].S.F,vt[i].S.S); i++; } ans[id]=(get(a)==get(b)); } for(ll i=1;i<=q;i++){ if(ans[i]) cout<<"TAIP\n"; else cout<<"NE\n"; } return; } int main(/*Aldk*/){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("hyper.in", "r", stdin); // freopen("hyper.out ", "w", stdout); //cout<<setprecision(6)<<fixed; int test=1; // cin>>test; for(int i=1;i<=test;i++){ solve(); cout<<'\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...