Submission #42459

# Submission time Handle Problem Language Result Execution time Memory
42459 2018-02-27T12:33:35 Z ruhanhabib39 Amusement Park (JOI17_amusement_park) C++14
0 / 100
82 ms 17392 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
   const int MAXN = 1e4;

   int N;
   vector<int> G[MAXN + 10];

   vector<int> tree[MAXN + 10];
   bool vis[MAXN + 10];

   vector<int> subtree[MAXN + 10];
   long long pos[MAXN + 10];

   void mst(int u) {
      vis[u] = true;
      for(int v : G[u]) {
         if(!vis[v]) {
            tree[u].push_back(v);
            tree[v].push_back(u);
            mst(v);
         }
      }
   }
   bool hasEdge(int u, int v) {
      return binary_search(tree[u].begin(), tree[u].end(), v);
   }
   void init_tree(int u, int p, vector<int>& subt) {
      if(subt.size() >= 60) return;
      pos[u] = subt.size(); subt.push_back(u);
      for(int v : tree[u]) {
         if(v != p) init_tree(v, u, subt);
      }
   }
   void work(int u, int p, vector<pair<int,int>> deg) {
      bool in = any_of(deg.begin(), deg.end(),
         [=](auto x) { return x.first == u; });

      if(!in) {
         auto rem = find_if(deg.begin(), deg.end(), 
            [=](auto x) { return x.first != p && x.second == 1; });

         assert(rem != deg.end());
         for(auto& it : deg) {
            if(hasEdge(rem->first, it.first)) it.second--;
         }
         pos[u] = pos[rem->first];
         *rem = {u, 1};
         auto ppos = find_if(deg.begin(), deg.end(), [=](auto x) { return x.first == p; });
         assert(ppos != deg.end());
         ppos->second++;
      }

      for(auto it : deg) subtree[u].push_back(it.first);
      for(int v : tree[u]) {
         if(v != p) work(v, u, deg);
      }
   }
   void build() {
      mst(0);
      for(int u = 0; u < N; u++) sort(tree[u].begin(), tree[u].end());
      vector<int> subt; init_tree(0, -1, subt);
      vector<pair<int,int>> deg;
      for(int u : subt) {
         int cc = count_if(subt.begin(), subt.end(),
               [=](int v) { return hasEdge(u, v); });
         deg.emplace_back(u, cc);
      }
      work(0, -1, deg);
   }
};

void Joi(int N_, int M, int A[], int B[], long long X, int T) {
   N = N_;
   for(int i = 0; i < M; i++) {
      G[A[i]].push_back(B[i]);
      G[B[i]].push_back(A[i]);
   }
   build();
   for(int i = 0; i < N; i++) {
      MessageBoard(i, bool(X & (1LL << pos[i])));
   }
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;


namespace {
   const int MAXN = 1e4;

   int N;
   vector<int> G[MAXN + 10];

   vector<int> tree[MAXN + 10];
   bool vis[MAXN + 10];

   vector<int> subtree[MAXN + 10];
   long long pos[MAXN + 10];

   void mst(int u) {
      vis[u] = true;
      for(int v : G[u]) {
         if(!vis[v]) {
            tree[u].push_back(v);
            tree[v].push_back(u);
            mst(v);
         }
      }
   }
   bool hasEdge(int u, int v) {
      return binary_search(tree[u].begin(), tree[u].end(), v);
   }
   void init_tree(int u, int p, vector<int>& subt) {
      if(subt.size() >= 60) return;
      pos[u] = subt.size(); subt.push_back(u);
      for(int v : tree[u]) {
         if(v != p) init_tree(v, u, subt);
      }
   }
   void work(int u, int p, vector<pair<int,int>> deg) {
      bool in = any_of(deg.begin(), deg.end(),
         [=](auto x) { return x.first == u; });

      if(!in) {
         auto rem = find_if(deg.begin(), deg.end(), 
            [=](auto x) { return x.first != p && x.second == 1; });

         for(auto& it : deg) {
            if(hasEdge(rem->first, it.first)) it.second--;
         }
         pos[u] = pos[rem->first];
         *rem = {u, 1};
         auto ppos = find_if(deg.begin(), deg.end(), [=](auto x) { return x.first == p; });
         assert(ppos != deg.end());
         ppos->second++;
      }

      for(auto it : deg) subtree[u].push_back(it.first);
      for(int v : tree[u]) {
         if(v != p) work(v, u, deg);
      }
   }
   void build() {
      mst(0);
      for(int u = 0; u < N; u++) sort(tree[u].begin(), tree[u].end());
      vector<int> subt; init_tree(0, -1, subt);
      vector<pair<int,int>> deg;
      for(int u : subt) {
         int cc = count_if(subt.begin(), subt.end(),
               [=](int v) { return hasEdge(u, v); });
         deg.emplace_back(u, cc);
      }
      work(0, -1, deg);
   }
   
   int res[60]; bool good[MAXN + 10];
   void solve(int u, int p = -1) {
      for(int v : tree[u]) {
         if(good[v] && v != p) {
            res[pos[v]] = Move(v);
            solve(v, u);
         }
      }
      if(p != -1) Move(p);
   }
};

long long Ioi(int N_, int M, int A[], int B[], int P, int V, int T) {
   N = N_;
   for(int i = 0; i < M; i++) {
      G[A[i]].push_back(B[i]);
      G[B[i]].push_back(A[i]);
   }
   build();

   fill(res, res + 60, -1);
   for(int u : subtree[P]) good[u] = true;
   res[pos[P]] = V;
   solve(P);

   long long X = 0;
   for(long long i = 0; i < 60; i++) {
      X |= res[i] << i;
   }
   return X;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2180 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 17236 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 17392 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 17392 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 17392 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -