Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC optimize ("O3")
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. const int MAXN = 3e5 + 1488;
  8.  
  9. vector<int> gr[MAXN];
  10. vector<int> t;
  11. vector<bool> used(MAXN);
  12. vector<int> tin(MAXN);
  13. vector<int> fup(MAXN);
  14.  
  15. int timer = 0;
  16.  
  17. void DFS(int v, int p = -1) {
  18. cout << "enter v " << v << endl;
  19. used[v] = true;
  20. fup[v] = tin[v] = timer++;
  21. for (int i = 0; i < gr[v].size(); ++i) {
  22. int to = gr[v][i];
  23. if (to == p) {
  24. continue;
  25. } else if (used[to]) {
  26. cout << "used to " << to << endl;
  27. cout << fup[v] << " " << tin[to] << "\n\n";
  28. fup[v] = min(fup[v], tin[to]);
  29. } else {
  30. DFS(to, v);
  31. cout << "v = " << v << endl;
  32. cout << fup[v] << " " << fup[to] << "\n\n";
  33. fup[v] = min(fup[v], fup[to]);
  34. if (fup[to] > tin[v]) {
  35. cout << v << " " << to << endl;
  36. }
  37. }
  38. }
  39. }
  40.  
  41. int main() {
  42. freopen("a.in", "r", stdin), freopen("a.out", "w", stdout);
  43. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  44. int n, m;
  45. cin >> n >> m;
  46. for (int i = 0; i < m; ++i) {
  47. int a, b;
  48. cin >> a >> b;
  49. gr[a].push_back(b);
  50. gr[b].push_back(a);
  51. }
  52. DFS(1);
  53. cout << endl;
  54. // for (int i = 1; i <= n; ++i) {
  55. // cout << "i = " << i << " " << tin[i] << " " << fup[i] << endl;
  56. // }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement