• 1149 Dangerous Goods Packaging


    When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂) must not be packed with flammable liquid (易燃液体), or it can cause explosion.

    Now you are given a long list of incompatible goods, and several lists of goods to be shipped. You are supposed to tell if all the goods in a list can be packed into the same container.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives two positive integers: N (≤104), the number of pairs of incompatible goods, and M (≤100), the number of lists of goods to be shipped.

    Then two blocks follow. The first block contains N pairs of incompatible goods, each pair occupies a line; and the second one contains M lists of goods to be shipped, each list occupies a line in the following format:

    K G[1] G[2] ... G[K]
    

    where K (≤1,000) is the number of goods and G[i]'s are the IDs of the goods. To make it simple, each good is represented by a 5-digit ID number. All the numbers in a line are separated by spaces.

    Output Specification:

    For each shipping list, print in a line Yes if there are no incompatible goods in the list, or No if not.

    Sample Input:

    1. 6 3
    2. 20001 20002
    3. 20003 20004
    4. 20005 20006
    5. 20003 20001
    6. 20005 20004
    7. 20004 20006
    8. 4 00001 20004 00002 20003
    9. 5 98823 20002 20003 20006 10010
    10. 3 12345 67890 23333

    Sample Output:

    1. No
    2. Yes
    3. Yes
    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. int n, m, k, u, v;
    6. int a[1010];
    7. vector<int>g[100010];
    8. int main() {
    9. cin >> n >> m;
    10. for (int i = 0; i < n; i++) {
    11. cin >> u >> v;
    12. g[u].push_back(v);
    13. g[v].push_back(u);
    14. }
    15. while (m--) {
    16. cin >> k;
    17. bool flag = 0;
    18. for (int i = 0; i < k; i++) {
    19. cin >> a[i];
    20. }
    21. for (int i = 0; i < k; i++) {
    22. if (flag) {
    23. break;
    24. }
    25. for (int j = i + 1; j < k; j++) {
    26. if (flag) {
    27. break;
    28. }
    29. for (int c = 0; c < g[a[i]].size(); c++) {
    30. if (g[a[i]][c] == a[j]) {
    31. flag = 1;
    32. break;
    33. }
    34. }
    35. }
    36. }
    37. if (flag) {
    38. cout << "No" << endl;
    39. } else {
    40. cout << "Yes" << endl;
    41. }
    42. }
    43. return 0;
    44. }

     

  • 相关阅读:
    webScoket长连接人性化解读
    项目常遇到的问题
    GAN 的理想损失值应该是多少?(Make Your First GAN With PyTorch 附录 A)
    PanNet: A deep network architecture for pan-sharpening(ICCV 2017)
    QT修改windowTitle的名字以及图片
    代理模式和单一职责原理一文读懂(设计模式与开发实践 P6)
    近期调研和使用 zeromq 与 cppzmq 的一些问题
    【MySQL】MySQL数据库的初阶使用
    JDBC快速入门和获取数据库的连接方式
    multiprocessing.pool详解
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/128158759