# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
890833 |
2023-12-22T04:00:57 Z |
Minbaev |
Jail (JOI22_jail) |
C++17 |
|
5 ms |
13144 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
vector<int>v[N],pred(N);
void solve(){
int n,m,k;
cin>>n;
for(int i = 1;i<=n;i++)v[i].clear();
for(int i = 1;i<n;i++){
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
cin>>m;
map<int,int>vis,vis1;
vector<int>time[n+1];
while(m--){
int a,b;
cin>>a>>b;
int timer = 0;
queue<pii>q;
q.push({a,0});
while(!q.empty()){
auto [x,pr] = q.front();
q.pop();
for(auto to:v[x]){
if(to==pr)continue;
pred[to] = x;
q.push({to,x});
}
}
vector<int>vs;
int y = b;
while(y!=a){
vs.pb(y);
y = pred[y];
}
vs.pb(a);
reverse(all(vs));
for(auto to:vs){
time[to].pb(timer);
//~ cout<<to<<" ";
timer++;
}
//~ cout<<"\n";
}
for(int i =1;i<=n;i++){
if(time[i].empty())continue;
sort(all(time[i]));
for(int j = 0;j<time[i].size()-1;j++){
if(time[i][j]==time[i][j+1]){
//~ cout<<i<<"\n";
cout<<"No\n";
return;
}
}
}
cout<<"Yes\n";
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;cin>>tt;
while(tt--)solve();
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:95:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int j = 0;j<time[i].size()-1;j++){
| ~^~~~~~~~~~~~~~~~~
jail.cpp:38:10: warning: unused variable 'k' [-Wunused-variable]
38 | int n,m,k;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
5 ms |
12892 KB |
Output is correct |
3 |
Incorrect |
4 ms |
12892 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Incorrect |
3 ms |
13144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Incorrect |
3 ms |
13144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Incorrect |
3 ms |
13144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Incorrect |
3 ms |
13144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Incorrect |
4 ms |
12892 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
5 ms |
12892 KB |
Output is correct |
3 |
Incorrect |
4 ms |
12892 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |