fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define pb push_back
  6. #define mp make_pair
  7.  
  8. typedef long long int ll;
  9. typedef pair<int, int> pii;
  10. typedef vector<int> vi;
  11. typedef vector<pii> vii;
  12.  
  13. ofstream fout ("closing.out");
  14. ifstream fin ("closing.in");
  15.  
  16. int N, M;
  17. int x, y;
  18. int open, found, c;
  19. vi adj[3001];
  20. vi close;
  21.  
  22. bool closed[3001];
  23. bool vis[3001];
  24.  
  25. void dfs(int v) {
  26. if (vis[v] || closed[v]) return;
  27. vis[v] = true;
  28.  
  29. for (auto const& w: adj[v]){
  30. if (!closed[w])
  31. dfs(w);
  32. }
  33. }
  34.  
  35. int main() {
  36. fin >> N >> M;
  37. for (int i = 0; i < M; i++) {
  38. fin >> x >> y;
  39. adj[x].pb(y);
  40. adj[y].pb(x);
  41. }
  42.  
  43. for (int i = 0; i < M; i++) {
  44. fin >> x;
  45. close.pb(x);
  46. }
  47.  
  48. open = N;
  49. for (int i = 0; i < N; i++) {
  50. memset(vis, 0, sizeof vis);
  51. c = 0;
  52.  
  53. for (int j = 1; j <= N; j++) {
  54. if (!vis[j] && !closed[j]) {
  55. dfs(j);
  56. c++;
  57. }
  58. }
  59.  
  60. if (c == 1)
  61. fout << "YES" << endl;
  62. else
  63. fout << "NO" << endl;
  64.  
  65. if (i < N - 1)
  66. closed[close[i]] = true;
  67. }
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty