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>
using namespace std;
//#define int unsigned short
int n,k,d,a;
int ans = 0;
vector<vector<int>> ady;
vector<vector<int>> adyd;
void dfs(int nodo, int sz, vector<int> c){
ans = max(ans,sz);
for(int x:adyd[nodo]) c[x]++;
for(int x:adyd[nodo]){
if(c[x]>=sz) dfs(x,sz+1,c); // todos los nodos "anteriores" están conectados
}
for(int x:adyd[nodo]) c[x]--;
}
int32_t main(){
cin >> n >> k;
ady = vector<vector<int>>(n,vector<int>());
adyd = vector<vector<int>>(n,vector<int>());
vector<int> deg(n);
for(int i=0;i<n;i++){
cin >> d;
deg[i] = d;
for(int j=0;j<d;j++){
cin >> a;
ady[i].push_back(a);
}
}
// paso a dirigido
for(int i=0;i<n;i++){
for(int vec:ady[i]){
if(deg[i]<deg[vec] or (deg[i]==deg[vec] and i<vec)) adyd[i].push_back(vec);
}
}
vector<int> c(n,0);
for(int i=0;i<n;i++){
dfs(i, 1, c);
}
cout << ans << endl;
}
# | 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... |