Skip to content

Instantly share code, notes, and snippets.

@key-moon

key-moon/b.cpp Secret

Created November 6, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save key-moon/5d178c83ac852458edd5e2f609d8ce58 to your computer and use it in GitHub Desktop.
Save key-moon/5d178c83ac852458edd5e2f609d8ce58 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define var auto
const char newl = '\n';
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { bool c = a > b; if (c) a = b; return c; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { bool c = a < b; if (c) a = b; return c; }
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int m, n, p;
while (cin >> m >> n >> p, m){
vector<bool> dp(m + 1);
dp[p] = true;
for (int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
dp[a] = dp[a] | dp[b];
dp[b] = dp[b] | dp[a];
}
int cnt = 0;
for (var&& elem : dp){
if (elem) cnt++;
}
cout << cnt << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment