[Ultraviolet A] 247-calling circles (Floyd judges that the package is closed and DFS outputs)

Source: Internet
Author: User

I am in poor status recently. I always love to make low-level mistakes. I have nothing to talk about. What I want to talk about is that Floyd may judge to close the package.

void Floyd()  {      for(int k=1; k<=n; k++)          for(int i=1; i<=n; i++)              if(map[i][k])                  for(int j=1; j<=n; j++)                      if(map[k][j])                          map[i][j] = 1;  }  


I have done a lot of graph theory before, and I feel that graph theory can cope with it in the past.

14059727 247 Calling circles Accepted C ++ 0.058 12:21:42

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <vector> # include <stack> # include <queue> # include <map> # include <set> # include <list> # include <cmath> # include <string> # include <sstream> # include <ctime> using namespace STD; # DEFINE _ pI ACOs (-1.0) # define ESP 1e-9 # define INF 1 <30 typedef long ll; typedef unsigned long ull; typedef pair <int, int> pill; /* ====================================== ====================================== Kinderriven ==== ========================================================== =======================*/# define maxd 25 + 1int N, m; Map <string, int> name; vector <string> name; int G [maxd] [maxd], ID; int vis [maxd]; void Init () {name. clear (); Name. clear (); Id = 0; memset (G, 0, sizeof (g); memset (VIS, 0, sizeof (VIS);} void DFS (int u) {vis [u] = 1; for (INT I = 0; I <n; I ++) if (G [u] [I] = 1 & G [u] [I] = G [I] [U]) {If (! Vis [I]) {cout <"," <name [I]; DFS (I) ;}} int main () {int case = 1; while (CIN> N> m) {Init (); If (! N &&! M) break; For (INT I = 0; I <m; I ++) {string S1, S2; CIN> S1> S2; If (! Name. Count (S1) {name [S1] = ID ++; name. push_back (S1) ;}if (! Name. count (S2) {name [s2] = ID ++; Name. push_back (S2);} int x = Name [S1], y = Name [s2]; /* Find the ID of the two strings */g [x] [Y] = 1;/* connect */} For (int K = 0; k <N; k ++) for (INT I = 0; I <n; I ++) if (G [I] [k]) for (Int J = 0; j <N; j ++) if (G [k] [J]) {G [I] [J] = 1;} If (Case> 1) cout <Endl; cout <"calling circles for Data Set" <Case ++ <":" <Endl; For (INT I = 0; I <n; I ++) {If (! Vis [I]) {cout <name [I]; DFS (I); cout <Endl ;}} return 0 ;} /* 5 5A ba BC de C */


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.