zoukankan      html  css  js  c++  java
  • 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 first 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 }
  • 相关阅读:
    Linux 目录结构
    Linux VI编辑器
    Linux试玩指令开机关机
    iBatis 的修改一个实体
    多功能截图工具(WinSnap)4.5.6 绿色汉化版(附注册码)
    源代码版本控制工具TortoiseSVN,AnkhSVN最新版本下载地址
    Node.js Tools for Visual Studio
    2015-12-1 Visual Studio 2015 Update 1发布
    ReactJS学习 相关网站
    A simple Test Client built on top of ASP.NET Web API Help Page
  • 原文地址:https://www.cnblogs.com/npugen/p/9721646.html
Copyright © 2011-2022 走看看