标签:print char 时间 输出 noip str struct lin getchar
★★☆ 输入文件:buss.in
输出文件:buss.out
简单对比
时间限制:1 s 内存限制:256 MB
按编号从小到大
5 6 1 2 2 3 3 4 4 1 2 5 5 2 1 0 0
1 2 3 4 5 1
1 #include <cstring> 2 #include <cstdio> 3 4 const int N(5000+15); 5 const int M(50000+5); 6 int head[N],sumedge; 7 struct Edge 8 { 9 int v,next; 10 Edge(int v=0,int next=0):v(v),next(next){} 11 }edge[M]; 12 inline void ins(int u,int v) 13 { 14 edge[++sumedge]=Edge(v,head[u]); 15 head[u]=sumedge; 16 } 17 18 #define min(a,b) (a<b?a:b) 19 int tim,dfn[N],low[N]; 20 int top,Stack[N],instack[N]; 21 int col[N],sumcol,cd[N]; 22 void DFS(int u) 23 { 24 low[u]=dfn[u]=++tim; 25 Stack[++top]=u; instack[u]=1; 26 for(int v,i=head[u];i;i=edge[i].next) 27 { 28 v=edge[i].v; 29 if(!dfn[v]) DFS(v), low[u]=min(low[u],low[v]); 30 else if(instack[v]) low[u]=min(low[u],dfn[v]); 31 } 32 if(low[u]==dfn[u]) 33 { 34 col[u]=++sumcol; 35 for(;Stack[top]!=u;top--) 36 { 37 instack[Stack[top]]=0; 38 col[Stack[top]]=sumcol; 39 } 40 instack[u]=0; top--; 41 } 42 } 43 44 inline void init() 45 { 46 sumedge=tim=top=sumcol=0; 47 memset(cd,0,sizeof(cd)); 48 memset(low,0,sizeof(low)); 49 memset(dfn,0,sizeof(dfn)); 50 // memset(col,0,sizeof(col)); 51 memset(edge,0,sizeof(edge)); 52 memset(head,0,sizeof(head)); 53 // memset(Stack,0,sizeof(Stack)); 54 memset(instack,0,sizeof(instack)); 55 } 56 inline void read(int &x) 57 { 58 x=0; register char ch=getchar(); 59 for(;ch>‘9‘||ch<‘0‘;) ch=getchar(); 60 for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar()) x=x*10+ch-‘0‘; 61 } 62 63 int AC() 64 { 65 freopen("buss.in","r",stdin); 66 freopen("buss.out","w",stdout); 67 for(int n,m;1;init()) 68 { 69 read(n); 70 if(!n) break; 71 read(m); 72 for(int u,v;m--;ins(u,v)) 73 read(u),read(v); 74 for(int i=1;i<=n;i++) 75 if(!dfn[i]) DFS(i); 76 for(int v,u=1;u<=n;u++) 77 for(int i=head[u];i;i=edge[i].next) 78 { 79 v=edge[i].v; 80 if(col[u]!=col[v]) cd[col[u]]++; 81 } 82 for(int i=1;i<=n;i++) 83 if(!cd[col[i]]) printf("%d ",i); 84 puts(""); 85 } 86 return 0; 87 } 88 89 int Hope=AC(); 90 int main(){;}
标签:print char 时间 输出 noip str struct lin getchar
原文地址:http://www.cnblogs.com/Shy-key/p/7466647.html