zoukankan      html  css  js  c++  java
  • [USACO09JAN]Earthquake Damage

    嘟嘟嘟

    刚开始因为没看到只能走没有损坏的农场,磨叽了20多分钟……不管了,写题解吧。

    首先如果一个点不能到达原点,那么和他相邻的点也不能到达原点,所以刚开始我们把不能走的点和他相邻的点都打上标记,然后跑dfs就行了。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<vector>
     8 #include<queue>
     9 #include<stack>
    10 #include<cctype>
    11 using namespace std;
    12 #define enter puts("")
    13 #define space putchar(' ')
    14 #define Mem(a) memset(a, 0, sizeof(a))
    15 typedef long long ll;
    16 typedef double db;
    17 const int INF = 0x3f3f3f3f;
    18 const db eps = 1e-8;
    19 const int maxn = 3e4 + 5;
    20 inline ll read()
    21 {
    22     ll ans = 0;
    23     char ch = getchar(), last = ' ';
    24     while(!isdigit(ch)) last = ch, ch = getchar();
    25     while(isdigit(ch)) ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar();
    26     if(last == '-') ans = -ans;
    27     return ans;
    28 }
    29 inline void write(ll x)
    30 { 
    31     if(x < 0) putchar('-'), x = -x;
    32     if(x >= 10) write(x / 10);
    33     putchar(x % 10 + '0');
    34 }
    35 
    36 int p, c, n;
    37 vector<int> v[maxn];
    38 bool vis[maxn];
    39 int ans;
    40 
    41 void dfs(int now)
    42 {
    43     vis[now] = 1; ans--;
    44     for(int i = 0; i < (int)v[now].size(); ++i)
    45         if(!vis[v[now][i]]) dfs(v[now][i]);
    46 }
    47 
    48 int main()
    49 {
    50     p = read(); c = read(); n = read();
    51     for(int i = 1; i <= c; ++i)
    52     {
    53         int x = read(), y = read();
    54         v[x].push_back(y); v[y].push_back(x);
    55     }
    56     for(int i = 1; i <= n; ++i)
    57     {
    58         int x = read(); vis[x] = 1;
    59         for(int j = 0; j < (int)v[x].size(); ++j) vis[v[x][j]] = 1;
    60     }
    61     ans = p; dfs(1);
    62     write(ans); enter;
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    GitLab 内存使用优化
    记一次 GitLab 的迁移过程
    MAC 最全快捷键
    IDEA中通过Java调用Python脚本报错
    远程服务调用PRC发展史
    分布式&微服务传送门
    (11)MySQL进阶篇SQL优化(InnoDB锁问题排查与解决)
    不懂物理的前端不是好的游戏开发者(一)—— 物理引擎基础
    京东购物小程序 | Taro3 项目分包实践
    浅谈树模型与集成学习-从决策树到GBDT
  • 原文地址:https://www.cnblogs.com/mrclr/p/9533069.html
Copyright © 2011-2022 走看看