标签:lin ble 训练 方向 event using red 迷宫 range
时限: 1000MS | 内存: 32768KB | 64位IO格式: %I64d & %I64u |
问题描述
输入
输出
样例输入
样例输出
来源
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #define maxn 1000000 5 using namespace std; 6 7 struct edge{ 8 int from,v; 9 }e[maxn]; 10 11 int tot,first[maxn]; 12 void insert(int u,int v){ 13 tot++; 14 e[tot].from = first[u]; 15 e[tot].v = v; 16 first[u] = tot; 17 } 18 19 bool vis[maxn]; 20 int color[maxn],n,m,dfn[maxn],low[maxn],TIM,COL,top,stack[maxn]; 21 22 void Tarjan(int p){ 23 dfn[p] = low[p] = ++TIM; 24 vis[p] = true; 25 stack[++top] = p; 26 for(int i = first[p];i;i = e[i].from){ 27 int v = e[i].v; 28 if(!dfn[v]){ 29 Tarjan(v); 30 low[p] = min(low[p],low[v]); 31 }else if(vis[v]) low[p] = min(low[p],dfn[v]); 32 } 33 34 if(dfn[p] == low[p]){ 35 ++COL; 36 color[p] = COL; 37 vis[p] = false; 38 while(stack[top] != p){ 39 color[stack[top]] = COL; 40 vis[stack[top--]] = false; 41 } 42 top--; 43 } 44 45 // printf("dfn[%d]: %d low[%d]: %d\n",p,dfn[p],p,low[p]); 46 47 } 48 49 int main(){ 50 51 while(1){ 52 memset(color,0,sizeof(color)); 53 memset(dfn,0,sizeof(dfn)); 54 memset(low,0,sizeof(low)); 55 memset(first,0,sizeof(first)); 56 tot = COL = TIM = top = 0; 57 scanf("%d%d",&n,&m); 58 59 if(!n && !m) return 0; 60 61 int a,b; 62 for(int i = 1;i <= m;i++){ 63 scanf("%d%d",&a,&b); 64 insert(a,b); 65 } 66 67 for(int i = 1;i <= n;i++) if(!dfn[i]) Tarjan(i); 68 69 if(COL == 1) printf("Yes\n",COL); 70 else printf("No\n"); 71 } 72 73 74 return 0; 75 }
标签:lin ble 训练 方向 event using red 迷宫 range
原文地址:http://www.cnblogs.com/Chorolop/p/7460265.html