Codeforces Goodbye B

Source: Internet
Author: User

/** *  @brief  good bye 2014 b *  @file  b.cpp *  @author  mianma *  @created  2014/01/06  10:20 *  @edited   2014/01/06   10:20 *  @type  dfs greedy  *  @note  */#include  < fstream> #include  <iostream> #include  <cstring> #include  <vector> #include  <set> #include  <stack> #include  <algorithm>using namespace std;# Define max (A, b)    ((a)  >  (b)  ?  (a)  :  (b)) #define  min (a, b)    ((a)  >  (b)  ?  (b)  :  (a))   #define &NBSP;ABS (a)        ((a)  >  0  ?  (a)  :  (0 -  (A))) # DEFINE&NBSP;CLR (VEC)    memset (vec, 0, sizeof (VEC)) #ifdef  debugifstream in;o fstream out; #define  Cin in#define cout out#else#define cin cin#define cout cout#endif#define  maxn 320int n;int table[maxn];int visit[maxn];vector<int> store;vector <int> record[maxn];set<int> dfs (int root) {    int pos  = root;    set<int> ret;    if (Visit[pos])          return ret;    stack<int> st;     st.push (POS);     while (!st.empty ()) {         int pos = st.top ();         st.pop ();         ret.insert (POS);         visit[pos] = 1;        for (int i = 0;  i < record[pOs].size ();  i++) {            if (visit[record[ Pos][i]])                  Continue;            st.push (Record[pos][i]);         }    }    return  RET;} Int main (void) {    ios_base::sync_with_stdio (0); #ifdef  DEBUG     cin.open ("./in",   ios::in);     cout.open ("./out",   ios::out); Endif    cin >> n;    for (int i = 1;  i <= n; i++)         CIN >>  Table[i];        char ch;    for (int i  = 1; i  <= n; i++)         for (int j = 1; j  <= n; j++) {            cin  >> ch;            if (' 1 '  == &NBSP;CH)                  Record[i].push_back (j);         }    for (int i  = 1; i <= n; i++) {    store.clear ();         set<int> st = dfs (i);     if (St.empty ())         continue;        for ( Set<int>::iterator iter = st.begin ();  iter != st.end ();  iter++)       &nBsp;              store.push_back (table[ *iter]);     sort (Store.begin (),  store.end ());         set<int>::iterator iter = st.begin ();         for (Int i = 0; i < store.size ();  i++, iter++)                  table[*iter] =  store[i];    }    for (int i = 1; i < =n; i++)         COUT << table[i] <<   (i == n ?  "\ n":  " ");         return 0;}


Codeforces Goodbye B

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.