답안 #205796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205796 2020-02-29T23:52:28 Z Mamnoon_Siam Pipes (CEOI15_pipes) C++17
0 / 100
1947 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

const int N = 1e5 + 5;

int n, m;
struct dsu {
  int par[N];
  dsu() {
    memset(par, 0, sizeof par);
    iota(par, par + N, 0);
  }
  int find(int u) {
    return u == par[u] ? u : par[u] = find(par[u]);
  }
  int unite(int u, int v) {
    u = find(u), v = find(v);
    if(u == v) return 0;
    par[u] = v;
    return 1;
  }
} ds1, ds2;

int low[N], in[N], tym = 0;
vector<int> g[N];

void dfs(int u, int dad = 0) {
  in[u] = low[u] = ++tym;
  for(int v : g[u]) if(v != dad) {
    if(in[v]) {
      low[u] = min(low[u], in[v]);
    } else {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if(low[v] > in[u]) {
        printf("%d %d\n", u, v);
      }
    }
  }
}

int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &m);
  for(int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if(!ds1.unite(u, v)) {
      if(ds2.unite(u, v)) {
        g[u].emplace_back(v);
        g[v].emplace_back(u);
      }
    } else {
      g[u].emplace_back(v);
      g[v].emplace_back(u);
    }
  }
  for(int i = 1; i <= n; i++) {
    if(!in[i]) {
      dfs(i);
    }
  }
  return 0;
}

Compilation message

pipes.cpp: In function 'int main(int, const char**)':
pipes.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &u, &v);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3448 KB Output is correct
2 Incorrect 7 ms 3448 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4244 KB Output is correct
2 Incorrect 11 ms 3704 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 9312 KB Output is correct
2 Incorrect 162 ms 8952 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Incorrect 288 ms 14032 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 461 ms 22024 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 628 ms 31096 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 989 ms 44624 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1314 ms 57208 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1612 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1947 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -