zoukankan      html  css  js  c++  java
  • POJ 2230 Watchcow

    题意:反正就是让你从1开始输出欧拉回路的路径

    题解:我也不是特别理解的套圈法

    Watchcow

     1 #include<cstring>
     2 #include<iostream>
     3 using namespace std;
     4 const int N = 20000+5;
     5 int head[N];
     6 int cnt = 0, n, m;
     7 struct Node
     8 {
     9     int nx;
    10     int to;
    11     bool vis;
    12 }Edge[N*5];
    13 void add_edge(int u, int v)
    14 {
    15     Edge[cnt].to = v;
    16     Edge[cnt].nx = head[u];
    17     Edge[cnt].vis = 1;
    18     head[u] = cnt++;
    19 }
    20 void dfs(int u)
    21 {
    22     for(int i = head[u]; ~i; i = Edge[i].nx)
    23     {
    24         if(Edge[i].vis)
    25         {
    26             Edge[i].vis = 0;
    27             dfs(Edge[i].to);
    28         }
    29     }
    30     cout << u << endl;
    31 }
    32 int main()
    33 {
    34     ios::sync_with_stdio(false);
    35     cin.tie(0);
    36     memset(head, -1, sizeof(head));
    37     cin >> n >> m;
    38     int u, v;
    39     for(int i = 1; i <= m; i++)
    40     {
    41         cin >> u >> v;
    42         add_edge(u, v);
    43         add_edge(v, u);
    44     }
    45     dfs(1);
    46     return 0;
    47 }
  • 相关阅读:
    poj 1840 简单哈希
    poj 2151概率dp
    poj 3349 简单hash
    poj3274 hash
    poj 1459 最大流 Dinic模板题
    poj 3436 最大流-拆点
    poj 3020 二分图最大匹配
    poj 1094 简单拓扑排序
    poj3687 反向建图拓扑排序
    poj 3267
  • 原文地址:https://www.cnblogs.com/MingSD/p/8418970.html
Copyright © 2011-2022 走看看