11175-From D to E and Back(思维)

Posted npugen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11175-From D to E and Back(思维)相关的知识,希望对你有一定的参考价值。

Problem UVA11175-From D to E and Back

Accept: 164  Submit: 607
Time Limit: 3000 mSec

技术分享图片 Problem Description

Take any directed graph D with n vertices and m edges. You can make the Lying graph E of B in the following way. E will have m vertices, one for each edge of D. For example, if D has an edge uv, then E will have a vertex called uv. Now, whenever D has edges uv and vw, E will have an edge from vertex uv to vertex vw. There are no other edges in E. You will be given a graph E and will have to determine whether it is possible for E to be the Lying graph of some directed graph D.

 

Input

The ?rst line of input gives the number of cases, N (N < 220). N test cases follow. Each one starts with two lines containing m (0 ≤ m ≤ 300) and k. The next k lines will each contain a pair of vertices, x and y, meaning that there is an edge from x to y in E. The vertices are numbered from 0 to m?1

 

技术分享图片 Output

For each test case, output one line containing ‘Case #x:’ followed by either ‘Yes’ or ‘No’, depending on whether E is a valid Lying graph or not. Note that D is allowed to have duplicate edges and self-edges.
 

技术分享图片 Sample Input

4 2 1 0 1 5 0 4 3 0 1 2 1 2 3 3 9 0 1 0 2 1 2 1 0 2 0 2 1 0 0 1 1 2 2
 

技术分享图片 Sample Output

Case #1: Yes

Case #2: Yes

Case #3: No

Case #4: Yes

 

题解:这种结论题真的是做不来。首先第一感觉是这怎么会不存在呢,然后样例三强势打脸,但是感觉上不成立的情况应该很少,但是少到何种程度完全没有认识,最后思来想去还是看了题解,题解都是千篇一律的结论,并且没有人证明那是充要的,至多证明是必要的,做这个题就当涨见识了。

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int maxn = 300 + 10;
 6 int gra[maxn][maxn];
 7 
 8 int m, t;
 9 
10 int read() {
11     int q = 0;
12     char ch =  ;
13     while (ch<0 || ch>9) ch = getchar();
14     while (0 <= ch && ch <= 9) {
15         q = q * 10 + ch - 0;
16         ch = getchar();
17     }
18     return q;
19 }
20 
21 bool solve() {
22     for (int i = 0; i < m; i++) {
23         for (int j = 0; j < m; j++) {
24             int f1 = 0, f2 = 0;
25             for (int k = 0; k < m; k++) {
26                 if (gra[i][k] && gra[j][k]) f1 = 1;
27                 if (gra[i][k] ^ gra[j][k]) f2 = 1;
28                 if (f1 && f2) return false;
29             }
30         }
31     }
32     return true;
33 }
34 
35 int T = 1;
36 
37 int main()
38 {
39     int iCase;
40     iCase = read();
41     while (iCase--) {
42         memset(gra, 0, sizeof(gra));
43         m = read(), t = read();
44         int u, v;
45         for (int i = 0; i < t; i++) {
46             u = read(), v = read();
47             gra[u][v] = 1;
48         }
49 
50         printf("Case #%d: ",T++);
51         if (solve()) printf("Yes
");
52         else printf("No
");
53     }
54     return 0;
55 }

 


以上是关于11175-From D to E and Back(思维)的主要内容,如果未能解决你的问题,请参考以下文章

UVA - 11175 From D to E and Back(思路)

springboot 新工程报错 Failed to configure a DataSource: 'url' attribute is not specified and no e

laravel发送邮件"Invalid ID given <67e72f21a23ae3b0bac504d418b5875a@->"

What exactly is the parameter e (event) and why pass it to JavaScript functions?

e585. Converting Between RGB and HSB Colors

How to cleanup ASM installation (RAC and Non-RAC) [ID 311350.1]