Submission #95117

# Submission time Handle Problem Language Result Execution time Memory
95117 2019-01-27T12:37:05 Z MrTEK Pipes (CEOI15_pipes) C++14
20 / 100
1320 ms 13232 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;

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

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 Incorrect 4 ms 2688 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3172 KB Output is correct
2 Incorrect 7 ms 2916 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 98 ms 3048 KB Output is correct
2 Incorrect 106 ms 2944 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 176 ms 3720 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 300 ms 5172 KB Output is correct
2 Correct 244 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 10084 KB Output is correct
2 Incorrect 379 ms 7208 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 634 ms 11100 KB Output is correct
2 Incorrect 583 ms 8600 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 849 ms 13152 KB Output is correct
2 Incorrect 771 ms 9092 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1042 ms 13232 KB Output is correct
2 Incorrect 1058 ms 9104 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 12524 KB Output is correct
2 Correct 1159 ms 10252 KB Output is correct