Ultraviolet a La 4255 Guess (topological arrangement)

Source: Internet
Author: User

Ultraviolet a La 4255 Guess (topological arrangement)

Topology arrangement applies to Directed Acyclic graphs (dags.

Construct One-Way edges between all nodes.

In a specific problem, abstract the outbound vertex and edge (unidirectional edge). The unidirectional edge corresponds to the size relationship or demand relationship between specific points.

After creating a plot, all the relationships in the problem can be expressed by directed edges between points.


In this question.

(1) It is not easy to represent each number when it is constructed into a point.

The prefix and construction are made into points, and all the intervals and values can have two prefixes. The size relationship between different prefixes can be obtained from all intervals and positive and negative values or 0, that is, the unidirectional edge between points.

(2) Notice that it may be zero, indicating that the two prefix values are equal, that is, there may be two points in the graph into the ring.

Solution:

Dis [I] [j] = 0, indicating equal, 1 indicating I --> j,-1 representing j -- I.

When a vertex is obtained, all dis [] [] = 0 is taken and assigned the same value.

//#pragma warning (disable: 4786)//#pragma comment (linker, "/STACK:16777216")//HEAD#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         #include 
          
           #include 
           
            #include 
            
             #include using namespace std;//LOOP#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FD(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))#define CPY(a, b) memcpy(a, b, sizeof(a))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RS(s) scanf("%s", s)//OUTPUT#define WI(n) printf("%d\n", n)#define WS(s) printf("%s\n", s)typedef long long LL;const int INF = 1000000007;const double eps = 1e-10;const int maxn = 20;int T, n;int suf[maxn];int dis[maxn][maxn];int du[maxn];vector
             
              a;void solve(){ int tot = 0; int val = 0; while (tot < n + 1) { for (int i = 0; i <= n; i++) { if (du[i] == 0) { a.clear(); a.push_back(i); suf[i] = val; for (int j = 0; j <= n; j++) { if (i != j && du[j] != -1 && dis[i][j] == 0) { suf[j] = val; a.push_back(j); } } val++; tot += a.size(); for (int j = 0; j < a.size(); j++) { int x = a[j]; for (int r = 0; r <= n; r++) if (du[r] != -1 && dis[x][r] == 1) du[r]--; } for (int j = 0; j < a.size(); j++) du[a[j]] = -1; } } } int x = suf[0]; for (int i = 0; i <= n; i++) suf[i] -= x; for (int i = 1; i <= n; i++) { if (i != 1) printf(" "); printf("%d", suf[i] - suf[i -1]); } puts("");}int main (){ scanf("%d",&T); while (T--) { scanf("%d", &n); memset(dis, 0, sizeof(dis)); memset(du, 0, sizeof(du)); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { char x; scanf(" %c", &x); if (x == '-') { du[i - 1]++; dis[j][i - 1] = 1; dis[i - 1][j] = -1; } else if (x == '+') { du[j]++; dis[i - 1][j] = 1; dis[j][i - 1] = -1; } } } solve(); } return 0;}
             
            
           
          
        
       
      
     
    
   
  
 


Related Article

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.