답안 #37745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37745 2017-12-27T13:40:53 Z funcsr Amusement Park (JOI17_amusement_park) C++14
10 / 100
175 ms 65152 KB
#include "Joi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <functional>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
  int N;
  vector<int> U, R;
  UF(int N) : N(N), U(N), R(N, 1) {
    rep(i, N) U[i] = i;
  }
  int find(int x) {
    if (U[x] == x) return x;
    return U[x] = find(U[x]);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (R[x] < R[y]) swap(x, y);
    U[y] = x;
    R[x] += R[y];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};


void Joi(int N, int M, int GA[], int GB[], long long X, int T) {
  int A[10000] = {};
  vector<int> G[10000];
  int deg[10000] = {};
  set<int> S[10000], leaf[10000];
  UF uf(N);
  rep(i, M) {
    int a = GA[i], b = GB[i];
    if (!uf.same(a, b)) {
      G[a].pb(b), G[b].pb(a);
      uf.unite(a, b);
    }
  }
  rep(i, N) A[i] = -1;
  set<int> used, lf;
  queue<P> q;
  q.push(P(0, -1));
  rep(i, 60) {
    int x = q.front()._1, p = q.front()._2; q.pop();
    A[x] = i;
    used.insert(x);
    if (p != -1) deg[x]++, deg[p]++;
    for (int t : G[x]) if (t != p) q.push(P(t, x));
  }
  rep(i, N) if (deg[i] == 1) lf.insert(i);
  for (int x : used) S[x] = used, leaf[x] = lf;

  while (!q.empty()) {
    int x = q.front()._1, p = q.front()._2; q.pop();
    S[x] = set<int>(S[p]);
    S[x].insert(x);
    leaf[x] = set<int>(leaf[p]);
    if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
    assert(!leaf[x].empty());
    int from = *leaf[x].begin();
    leaf[x].erase(from);
    S[x].erase(from);
    int ch = -1;
    for (int x : G[from]) if (S[x].find(x) != S[x].end()) ch = x;
    int deg = 0;
    for (int t : G[ch]) if (S[x].find(t) != S[x].end()) deg++;
    if (deg == 1) leaf[x].insert(ch);
    A[x] = A[from];
    leaf[x].insert(x);
    for (int t : G[x]) if (t != p) q.push(P(t, x));
  }
  rep(i, N) assert(S[i].size() == 60);
  rep(i, N) MessageBoard(i, (X>>A[i])&1);
}
#include "Ioi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <functional>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
  int N;
  vector<int> U, R;
  UF(int N) : N(N), U(N), R(N, 1) {
    rep(i, N) U[i] = i;
  }
  int find(int x) {
    if (U[x] == x) return x;
    return U[x] = find(U[x]);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (R[x] < R[y]) swap(x, y);
    U[y] = x;
    R[x] += R[y];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

long long Ioi(int N, int M, int GA[], int GB[], int start, int V, int T) {
  int A[10000] = {};
  vector<int> G[10000];
  int deg[10000] = {};
  set<int> S[10000], leaf[10000];
  UF uf(N);
  rep(i, M) {
    int a = GA[i], b = GB[i];
    if (!uf.same(a, b)) {
      G[a].pb(b), G[b].pb(a);
      uf.unite(a, b);
    }
  }
  rep(i, N) A[i] = -1;
  set<int> used, lf;
  queue<P> q;
  q.push(P(0, -1));
  rep(i, 60) {
    int x = q.front()._1, p = q.front()._2; q.pop();
    A[x] = i;
    used.insert(x);
    if (p != -1) deg[x]++, deg[p]++;
    for (int t : G[x]) if (t != p) q.push(P(t, x));
  }
  rep(i, N) if (deg[i] == 1) lf.insert(i);
  for (int x : used) S[x] = used, leaf[x] = lf;

  while (!q.empty()) {
    int x = q.front()._1, p = q.front()._2; q.pop();
    S[x] = set<int>(S[p]);
    S[x].insert(x);
    leaf[x] = set<int>(leaf[p]);
    if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
    assert(!leaf[x].empty());
    int from = *leaf[x].begin();
    leaf[x].erase(from);
    S[x].erase(from);
    int ch = -1;
    for (int x : G[from]) if (S[x].find(x) != S[x].end()) ch = x;
    int deg = 0;
    for (int t : G[ch]) if (S[x].find(t) != S[x].end()) deg++;
    if (deg == 1) leaf[x].insert(ch);
    A[x] = A[from];
    leaf[x].insert(x);
    for (int t : G[x]) if (t != p) q.push(P(t, x));
  }
  rep(i, N) assert(S[i].size() == 60);
  long long X = 0;
  function<void(int, int, int)> dfs = [&](int x, int p, int v) {
    X |= ((long long)v<<A[x]);
    for (int t : G[x]) if (t != p && S[start].find(t) != S[start].end()) {
      dfs(t, x, Move(t));
      Move(x);
    }
  };
  dfs(start, -1, V);
  return X;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7544 KB Output is correct
2 Correct 0 ms 8340 KB Output is correct
3 Correct 6 ms 9924 KB Output is correct
4 Runtime error 0 ms 3792 KB Execution killed because of forbidden syscall gettid (186)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 21636 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7552 KB Output is correct
2 Correct 0 ms 7552 KB Output is correct
3 Correct 0 ms 7552 KB Output is correct
4 Correct 9 ms 16524 KB Output is correct
5 Correct 22 ms 16532 KB Output is correct
6 Correct 22 ms 16528 KB Output is correct
7 Correct 25 ms 16524 KB Output is correct
8 Correct 25 ms 16532 KB Output is correct
9 Correct 164 ms 65152 KB Output is correct
10 Correct 172 ms 65144 KB Output is correct
11 Correct 175 ms 65148 KB Output is correct
12 Correct 0 ms 7548 KB Output is correct
13 Correct 0 ms 7548 KB Output is correct
14 Correct 0 ms 7296 KB Output is correct
15 Correct 0 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 17408 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 9096 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -