Submission #95119

# Submission time Handle Problem Language Result Execution time Memory
95119 2019-01-27T12:49:24 Z MrTEK Pipes (CEOI15_pipes) C++14
100 / 100
1222 ms 13156 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

int n,m,u,v,t,tin[N],fup[N];
vector <int> ed[N];
bool vis[N];

class dsu { public:
  int dad[N];
  void init() {
    for (int i = 1 ; i <= n ; i++)
      dad[i] = i;
  }

  int find(int x) {
    if (x == dad[x])
      return x;
    return dad[x] = find(dad[x]);
  }

  bool merge(int x,int y) {
    int dx = find(x) , dy = find(y);
    if (dx == dy)
      return false;
    dad[dx] = dy;
    return true;
  }
}t1,t2;

int dfs(int cur,int par) {
  vis[cur] = true;
  tin[cur] = fup[cur] = ++t;
  int cnt = 0;
  for (auto i : ed[cur]) {
    if (i == par) {
      cnt++;
      continue;
    }
    if (vis[i])
      fup[cur] = min(fup[cur],tin[i]);
    else{
      int temp = dfs(i,cur);
      fup[cur] = min(fup[cur],fup[i]);
      if (fup[i] > tin[cur] && temp == 1)
        cout << cur << " " << i << "\n";
    }
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  t1.init();
  t2.init();
  for (int i = 1 ; i <= m ; i++) {
    cin >> u >> v;
    if (t1.merge(u,v) || t2.merge(u,v)) {
      ed[u].push_back(v);
      ed[v].push_back(u);
    }
  }
  for (int i = 1 ; i <= n ; i++)
    if (vis[i] == false)
      dfs(i,-1);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3200 KB Output is correct
2 Correct 7 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 3036 KB Output is correct
2 Correct 93 ms 2912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 3692 KB Output is correct
2 Correct 184 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 5180 KB Output is correct
2 Correct 239 ms 4872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 10092 KB Output is correct
2 Correct 362 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 628 ms 11144 KB Output is correct
2 Correct 653 ms 8656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 809 ms 13156 KB Output is correct
2 Correct 758 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1124 ms 13148 KB Output is correct
2 Correct 968 ms 9076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1222 ms 12536 KB Output is correct
2 Correct 1150 ms 10156 KB Output is correct