답안 #94783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94783 2019-01-23T20:38:43 Z WLZ Conspiracy (POI11_kon) C++17
0 / 100
1983 ms 132096 KB
#include <bits/stdc++.h>
using namespace std;

int n;
vector< vector<int> > g;
vector< vector<int> > tg;
vector< vector<int> > mat;
vector<int> was;
vector<int> topoSort;
vector<int> scc;
int cur = 1;
vector<int> as;

void add_edge(int u, int v){
  g[u].push_back(v);
  tg[v].push_back(u);
}

void dfs1(int u) {
  was[u] = 1;
  for (auto& v : g[u]) {
    if (!was[v]) {
      dfs1(v);
    }
  }
  topoSort.push_back(u);
}

void dfs2(int u) {
  scc[u] = cur;
  for (auto& v : tg[u]) {
    if (scc[v] == -1) {
      dfs2(v);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  mat.assign(n + 1, vector<int>(n + 1, 0));
  g.resize(2 * n + 1);
  tg.resize(2 * n + 1);
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int a;
      cin >> a;
      mat[a][k] = mat[k][a] = 1;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (mat[i][j]) {
        add_edge(i, j + n);
        add_edge(j, i + n);
      } else {
        add_edge(i + n, j);
        add_edge(j + n, i);
      }
    }
  }
  was.assign(2 * n + 1, 0);
  for (int i = 1; i <= 2 * n; i++) {
    if (!was[i]) {
      dfs1(i);
    }
  }
  scc.assign(2 * n + 1, -1);
  reverse(topoSort.begin(), topoSort.end());
  for (auto& i : topoSort) {
    if (scc[i] == -1) {
      dfs2(i);
      cur++;
    }
  }
  as.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    if (scc[i] == scc[i + n]) {
      cout << 0 << '\n';
      return 0;
    }
    as[i] = scc[i] > scc[i + n];
  }
  int ans = 1;
  int sup = 0, con = 0;
  for (int i = 1; i <= n; i++) {
    if (as[i]) {
      int pos = 1;
      for (int j = 1; j <= n; j++) {
        if (!as[j] && !mat[i][j]) {
          pos = 0;
          break;
        }
      }
      ans += pos;
    } else {
      int pos = 1;
      for (int j = 1; j <= n; j++) {
        if (as[j] && mat[i][j]) {
          pos = 0;
          break;
        }
      }
      ans += pos;
    }
    sup += 1 - as[i];
    con += as[i];
  }
  vector< set<int> > st(n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == i) {
        continue;
      }
      if (as[i] && mat[i][j]) {
        st[i].insert(j);
      } 
      if (!as[i] && !mat[i][j]) {
        st[i].insert(j);
      }
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (as[i] != as[j]) {
        int x = i, y = j;
        if (as[x]) {
          swap(x, y);
        }
        if (((int) st[x].size() == con || ((int) st[x].size() == con - 1 && !st[x].count(y))) && ((int) st[y].size() == sup || ((int) st[y].size() == sup - 1 && !st[y].count(x)))) {
          ans++;
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Incorrect 5 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1016 KB Output is correct
2 Incorrect 7 ms 1528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 30276 KB Output is correct
2 Incorrect 141 ms 38408 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 36472 KB Output is correct
2 Incorrect 255 ms 52340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 109432 KB Output is correct
2 Incorrect 598 ms 122284 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 525 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1983 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -