답안 #439413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439413 2021-06-29T18:45:33 Z prvocislo 낙하산 고리들 (IOI12_rings) C++17
0 / 100
4000 ms 70888 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n;
vector<int> g[maxn];
vector<pair<int, int> > e;
struct dsu
{
  int p[maxn], deg[maxn], ok, r;
  int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
  void merge(int a, int b)
  {
    if (r == a || r == b) return;
    if (deg[a] == 2 || deg[b] == 2 || find(a) == find(b)) return ok = 0, void();
    deg[a]++, deg[b]++;
    p[find(a)] = find(b);
  }
  dsu(int root)
  {
    ok = 1, r = root;
    for (int i = 0; i < n; i++) p[i] = i, deg[i] = 0;
    for (pair<int, int> i : e) merge(i.first, i.second);
  }
};
int p[maxn], s[maxn], cycle = 0;
bool bad = false;
vector<dsu> sp;
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
bool merge(int a, int b)
{
  a = find(a), b = find(b);
  if (a == b) return false;
  p[b] = a, s[a] += s[b];
  return true;
}
void Init(int N_) {
  n = N_;
  for (int i = 0; i < n; i++) p[i] = i, s[i] = 1;
}
void Link(int a, int b) {
  if (bad) return;
  g[a].push_back(b), g[b].push_back(a); e.push_back({a, b});
  for (dsu &i : sp) i.merge(a, b);
  if (g[a].size() < g[b].size()) swap(a, b);
  if (g[a].size() == 3)
  {
    if (sp.size()) return;
    sp.push_back(dsu(a));
    for (int i : g[a]) sp.push_back(dsu(i));
    return; 
  }
  if (!merge(a, b))
  {
    if (cycle) return bad = true, void();
    cycle = s[a];
  }
}
int CountCritical() {
  if (bad) return 0;
  if (sp.size())
  {
    int ans = 0;
    for (dsu &i : sp) ans += i.ok;
    return ans;
  }
  return cycle ? cycle : n;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 139 ms 70888 KB Output is correct
3 Correct 160 ms 70860 KB Output is correct
4 Incorrect 42 ms 31564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4075 ms 42424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 139 ms 70888 KB Output is correct
3 Correct 160 ms 70860 KB Output is correct
4 Incorrect 42 ms 31564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 139 ms 70888 KB Output is correct
3 Correct 160 ms 70860 KB Output is correct
4 Incorrect 42 ms 31564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 139 ms 70888 KB Output is correct
3 Correct 160 ms 70860 KB Output is correct
4 Incorrect 42 ms 31564 KB Output isn't correct
5 Halted 0 ms 0 KB -