Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Выяснить есть ли в графе путь из вершины i в вершину j. */
- #include <stdlib.h>
- #include <time.h>
- #include <stdio.h>
- typedef unsigned int word;
- word inbool(int n)
- {
- word res=0,mask=1;
- char s[33];
- gets(s);
- for(int i=0;i<n;++i,mask<<=1)
- {
- if(s[i]=='1') res|=mask;
- }
- return res;
- }
- void outbool(word v, int n)
- {
- word mask=1;
- for(int i=0; i<n;++i,mask<<=1)
- {
- if(v&mask) printf("1");
- else printf("0");
- }
- printf("\n");
- }
- void main()
- {
- int n,i,j;
- word m[32],res=0,to_look=0,looked=0;
- /*
- res-вершины, которые надо просмотреть в следующем цикле
- to_look- мн-во, которое надо просмотреть
- looked- просмотренные вершины
- */
- scanf("%d",&n);
- fflush(stdin);
- for(int i=0; i<n; ++i)
- m[i]=inbool(n);
- putchar('\n');
- scanf("%d %d",&i,&j);
- to_look=1<<i;
- while(to_look)
- {
- for(int i=0; i<n;i++) //перебираем все вершины из to_look и запоминаем их соседей
- if(to_look&(1<<i)) res|=m[i]; //два амперсанда
- if(res&(1<<j))
- {
- printf("yes\n");
- return;
- }
- looked|=to_look;
- to_look=res^(looked&res);
- }
- printf("no\n");
- }
Add Comment
Please, Sign In to add comment