Title Address: HDU 1827
To indent a point, after you have shrunk the points, find the block with a degree of 0 in it that needs to be passed. It then spends the least amount of money in the block to represent the cost of the block. Add up on the line.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64#define Pi ACOs ( -1.0) const int Mod=1e9+7;const int Inf=0x3f3f3f3f;const double eqs=1e-9;c onst int Maxn=1000+10;const int maxm=2000+10;int HEAD[MAXN], CNT, indx, top, Ans;int LOW[MAXN], DFN[MAXN], BELONG[MAXN], I NSTACK[MAXN], STK[MAXN], COST[MAXN], D[MAXN], in[maxn];struct node{int u, V, next;} edge[maxm];void Add (int u, int v) {edge[cnt].u=u; Edge[cnt].v=v; Edge[cnt].next=head[u]; head[u]=cnt++;} void Tarjan (int u) {low[u]=dfn[u]=++indx; Instack[u]=1; Stk[++top]=u; for (int i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].v; if (!dfn[v]) {Tarjan (v); Low[u]=min (Low[u],low[v]); } elsE if (Instack[v]) {low[u]=min (low[u],dfn[v]); }} if (Low[u]==dfn[u]) {ans++; while (1) {int v=stk[top--]; instack[v]=0; Belong[v]=ans; if (u==v) break; }}}void init () {memset (head,-1,sizeof (head)); memset (instack,0,sizeof (instack)); memset (dfn,0,sizeof (DFN)); memset (cost,inf,sizeof (cost)); memset (In,0,sizeof (in)); Cnt=top=indx=ans=0;} int main () {int n, m, I, u, V, sum, tot; while (scanf ("%d%d", &n,&m)!=eof) {init (); for (i=1;i<=n;i++) {scanf ("%d", &d[i]); } while (m--) {scanf ("%d%d", &u,&v); Add (U,V); } for (i=1;i<=n;i++) {if (!dfn[i]) Tarjan (i); }//printf ("ans=%d\n", ans); for (i=0;i<cnt;i++) {if (BELONG[EDGE[I].U]!=BELONG[EDGE[I].V]) in[b elong[edge[i].v]]++; } sum=tot=0; for (i=1;i<=n;i++) {if (Cost[belong[i]]>d[i]) cost[belong[i]]=d[ I]; } for (i=1;i<=ans;i++) {if (!in[i]) {tot++; Sum+=cost[i]; }} printf ("%d%d\n", tot,sum); } return 0;}
HDU 1827 Summer Holiday (strong connected component)