题目描述
对于任务A,即求缩点后入度为0的点的个数
对于任务B,要使整个图连通,则入度0的点需要拓展一条入边,出度0的点需要拓展一条出边,那么需要拓展的最少边数即为max(入度0点数,出度0点数);特别的,当本来整个图连通时,不需要拓展代码
#include#include #include #include #include using namespace std;const int N=110,M=N*N;int ans,n,top,cnt1,cnt2,s[N],deg[N],q[N],e[N][N];int tot,idx,dfn[N],low[N],col[N],vis[N];vector g[N];int read(){ int out=0,f=1;char c=getchar(); while(c > '9' || c < '0') { if(c == '-') f=-1; c=getchar();} while(c <= '9' && c >= '0') {out=(out<<1)+(out<<3)+c-'0';c=getchar();} return out*f;}void init(){ n=read(); for(int i=1;i<=n;i++) { int x; while(x=read()) {g[i].push_back(x);} }}void tarjan(int u){ dfn[u]=low[u]=++idx;s[++top]=u;vis[u]=1; for(unsigned int i=0;i