What Is the biggest Smarter? (DP)
Link to the question: Click to open the link DAG (directed acyclic graph). The longest path + print path graph creation is very simple. For two points a B, the condition from a to B is w [a]. S [B] attention is directed graph. Set dp [I] to the longest path length starting with I, dp [I] = max (dp [I], dp [j] + 1) enumeration j (j is a point connected to I)
#include #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define maxn 1010#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair
#define ull unsigned long longusing namespace std;int p,w[maxn],s[maxn],dp[maxn];bool ma[maxn][maxn];void build(){memset(ma,0,sizeof(ma));for(int i=1;i
s[j])ma[i][j]=1;else if(w[j]
s[i])ma[j][i]=1;}}}int dfs(int x){int& ans=dp[x];if(ans>0) return ans;ans=1;for(int i=1;i