This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
/*
⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⢻⣿⣿⣿⣿⣿⣿⣿⣿⣯⢻⣿⣿⣿⣿⣆⠄⠄⠄
⠄⠄⣼⢀⣿⣿⣿⣿⣏⡏⠄⠹⣿⣿⣿⣿⣿⣿⣿⣿⣧⢻⣿⣿⣿⣿⡆⠄⠄
⠄⠄⡟⣼⣿⣿⣿⣿⣿⠄⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⣿⣇⢻⣿⣿⣿⣿⠄⠄
⠄⢰⠃⣿⣿⠿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠙⠿⣿⣿⣿⣿⣿⠄⢿⣿⣿⣿⡄⠄
⠄⢸⢠⣿⣿⣧⡙⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠈⠛⢿⣿⣿⡇⠸⣿⡿⣸⡇⠄
⠄⠈⡆⣿⣿⣿⣿⣦⡙⠳⠄⠄⠄⠄⠄⠄⢀⣠⣤⣀⣈⠙⠃⠄⠿⢇⣿⡇⠄
⠄⠄⡇⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⣠⣶⣿⣿⣿⣿⣿⣿⣷⣆⡀⣼⣿⡇⠄
⠄⠄⢹⡘⣿⣿⣿⢿⣷⡀⠄⢀⣴⣾⣟⠉⠉⠉⠉⣽⣿⣿⣿⣿⠇⢹⣿⠃⠄
⠄⠄⠄⢷⡘⢿⣿⣎⢻⣷⠰⣿⣿⣿⣿⣦⣀⣀⣴⣿⣿⣿⠟⢫⡾⢸⡟⠄.
⠄⠄⠄⠄⠻⣦⡙⠿⣧⠙⢷⠙⠻⠿⢿⡿⠿⠿⠛⠋⠉⠄⠂⠘⠁⠞⠄⠄⠄
⠄⠄⠄⠄⠄⠈⠙⠑⣠⣤⣴⡖⠄⠿⣋⣉⣉⡁⠄⢾⣦⠄⠄⠄⠄⠄⠄⠄⠄
*/
typedef unsigned long long ull;
using namespace std;
const int N=1e4+5;
int g,n,m;
vector<int> adj[N],det[N],dp[N];
vector<vector<int>> mut[N];
bool comp[N][N],vis[N][N],calc[N],able[N];
void dfs(int x,int s){
vis[s][x]=true;
for (auto u:adj[x]){
if (vis[s][u]) continue;
dfs(u,s);
}return;
}
void rec(int x){
if (calc[x]) return;
calc[x]=true;able[x]=true;
vector<int> v;
for (auto u:mut[x][0]){
if (u<2) {v.pb(u);continue;}
if (vis[u][x] && vis[x][u]) {able[x]=0;break;}
rec(u);
if (!able[u]){
able[x]=0;
break;
}
for (auto y:dp[u]) v.pb(y);
}
if (able[x]) dp[x]=v;
return;
}
bool check(int x){
for (int i=1;i<=m;i++){
for (int j=0;j+(int)det[i].size()-1<(int)dp[x].size();j++){
bool eq=true;
for (int k=j;k<j+(int)det[i].size();k++) eq&=(dp[x][k]==det[i][k-j]);
if (eq) return 1;
}
}return 0;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>g>>n>>m;
for (int i=1;i<=n;i++){
int x,k;cin>>x>>k;
vector<int> v(k);
for (int j=0;j<k;j++){
cin>>v[j];
if (v[j]>1) adj[x].pb(v[j]);
}
mut[x].pb(v);
}
for (int i=2;i<g;i++) dfs(i,i);
for (int i=1;i<=m;i++){
int l;cin>>l;
det[i].resize(l);
for (int j=0;j<l;j++) cin>>det[i][j];
}
for (int i=2;i<g;i++){
rec(i);
//for (auto u:dp[i]) cout<<u<<' ';cout<<endl;
if (!able[i]){
cout<<"YES"<<endl;
continue;
}
bool y=check(i);
if (y) cout<<"YES"<<endl;
else cout<<"NO "<<dp[i].size()<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |