Submission #949251

#TimeUsernameProblemLanguageResultExecution timeMemory
949251hotboy2703Jail (JOI22_jail)C++14
0 / 100
5050 ms17456 KiB
#include<bits/stdc++.h> using ll = long long; using namespace std; #define pll pair <ll,ll> #define fi first #define se second #define sz(a) (ll((a).size())) #define BIT(mask,i) (((mask) >> (i))&1) #define MASK(i) (1LL << (i)) #define MP make_pair ll t,n,m; const ll MAXN = 1.2e5; vector <ll> g1[MAXN+100]; vector <ll> g2[MAXN+100]; pll a[MAXN+100]; ll st[MAXN+100]; ll trace[MAXN+100]; ll en[MAXN+100]; bool in[MAXN+100]; bool in_st[MAXN+100]; bool detect_cycle = 0; vector <ll> find_path(ll x,ll y){ for (ll i = 1;i <= n;i ++)trace[i] = 0; trace[x] = x; queue <ll> q; q.push(x); while (!q.empty()){ ll u = q.front(); q.pop(); for (auto v:g1[u]){ if (!trace[v]){ trace[v] = u; q.push(v); } } } ll cur=y; // cout<<"WOW "<<endl; vector <ll> res; do{ res.push_back(cur); cur = trace[cur]; // cout<<cur<<endl; }while (cur != x); // cout<<"WHAT "<<endl; reverse(res.begin(),res.end()); return res; } void dfs(ll u){ in[u] = 1; in_st[u] = 1; for (auto v:g2[u]){ if (in_st[v])detect_cycle = 1; if (in[v])continue; dfs(v); } in_st[u] = 0; } int main(){ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); cin>>t; while (t--){ cin>>n; detect_cycle = 0; for (ll i = 1;i <= n;i ++){ g1[i].clear(); g2[i].clear(); st[i] = 0; en[i] = 0; in[i] = in_st[i] = 0; } for (ll i = 1;i < n;i ++){ ll u,v; cin>>u>>v; g1[u].push_back(v); g1[v].push_back(u); } cin>>m; for (ll i = 1;i <= m;i ++){ cin>>a[i].fi>>a[i].se; st[a[i].fi] = i; en[a[i].se] = i; } bool ok = 1; while (ok){ ok = 0; for (ll i = 1;i <= m;i ++){ if (a[i].fi != a[i].se){ ll nxt = a[i].fi + (a[i].fi < a[i].se ? 1 : -1); if (nxt <= n && nxt >= 1 && st[nxt] == 0){ swap(st[nxt],st[a[i].fi]); a[i].fi = nxt; ok = 1; } } // cout<<a[i].fi<<' '<<a[i].se<<'\n'; } } ok = 1; for (ll i = 1;i <= m;i ++){ if (a[i].fi != a[i].se)ok = 0; } cout<<(ok?"Yes":"No")<<'\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...