Submission #891017

#TimeUsernameProblemLanguageResultExecution timeMemory
891017abushbandit_1Jail (JOI22_jail)C++17
0 / 100
5078 ms464 KiB
/* author : abushbandit contest : --- */ #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define ff first #define ss second #define pb push_back #define rep(i,s,f) for(int i = s;i < f;i++) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #pragma GCC optimize("Ofast,no-stack-protector,fast-math",3) template <class type1> using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<pair<int,int>> vii; typedef pair<int,int> pii; const ll INF = 1e18; const ll MOD7 = 1e9 + 7; const ll MOD9 = 998244353; const ld PI = acos(-1.0); const int N = 120000 + 2; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } int binpow (int a, int n) { int res = 1; while (n) { if (n & 1) res *= a; a *= a; n >>= 1; } return res; } void start_file(string file){ freopen((file + ".in").c_str(),"r",stdin); freopen((file + ".out").c_str(),"w",stdout); } void solve() { int n; cin >> n; vector<vector<int>> g(n + 1); for(int i = 0;i < n - 1;i++){ int a,b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } int m; cin >> m; int s[m + 1],t[m + 1]; vector<int> v; for(int i = 1;i <= m;i++){ cin >> s[i] >> t[i]; v.pb(i); } //~ cout << m << endl; do{ bool check = 1; vector<int> ans(n + 1); for(int i = 0;i < m;i++){ vector<int> dis(n + 1); queue<pair<int,int>> q; q.push({s[v[i]],-1}); dis[s[v[i]]] = 1; vector<int> pr(n + 1); pr[s[v[i]]] = -1; while(!q.empty()){ auto [w,p] = q.front(); q.pop(); for(auto u : g[w]){ if(u != p){ dis[u] = dis[w] + 1; pr[u] = w; q.push({u,w}); } } } int y = t[v[i]]; while(y != -1){ if(ans[y] == 1){ check = 0; break; } y = pr[y]; } if(!check){ break; } ans[t[v[i]]] = 1; } if(check){ cout << "Yes" << '\n'; return; } }while(next_permutation(all(v))); cout << "No" << '\n'; } signed main() { ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int t = 1; cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

jail.cpp: In function 'void start_file(std::string)':
jail.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  freopen((file + ".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jail.cpp:76:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  freopen((file + ".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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...