Submission #228135

#TimeUsernameProblemLanguageResultExecution timeMemory
228135qkxwsmAmusement Park (JOI17_amusement_park)C++14
0 / 100
56 ms9420 KiB
#include "Joi.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; static const int MAXN = 10013; static const int MAGIC = 60; static int N, R; static vi edge[MAXN]; static int dsu[MAXN]; static vi ord; static vi nodes[MAXN]; static bool vis[MAXN], inside[MAXN]; static int parent[MAXN], label[MAXN]; static int get(int u) { return (u == dsu[u] ? u : dsu[u] = get(dsu[u])); } static bool merge(int u, int v) { u = get(u); v = get(v); if (u == v) { return false; } dsu[u] = v; return true; } static void gen() { //generates all the labels for all the nodes. queue<int> q; q.push(0); while(!q.empty()) { int u = q.front(); q.pop(); label[u] = SZ(nodes[0]); nodes[0].PB(u); vis[u] = true; if (SZ(nodes[0]) == MAGIC) { break; } for (int v : edge[u]) { if (vis[v]) { continue; } parent[v] = u; q.push(v); } } FOR(i, 1, SZ(nodes[0])) { nodes[nodes[0][i]] = nodes[0]; } while(!q.empty()) { int u = q.front(); q.pop(); vis[u] = true; for (int v : nodes[parent[u]]) { inside[v] = true; } nodes[u] = nodes[parent[u]]; FOR(i, 0, SZ(nodes[parent[u]])) { int v = nodes[parent[u]][i]; if (v == parent[u]) continue; int c = 0; for (int x : edge[v]) { if (inside[x]) c++; } if (c == 1) { label[u] = label[v]; nodes[u][i] = u; break; } } for (int v : nodes[parent[u]]) { inside[v] = false; //you just wanna find any leaf, except w } for (int v : edge[u]) { if (vis[v]) { continue; } parent[v] = u; q.push(v); } } } void Joi(int n, int m, int e1[], int e2[], ll val, int subtask) { N = n; iota(dsu, dsu + N, 0); FOR(i, 0, m) { int u = e1[i], v = e2[i]; if (merge(u, v)) { edge[u].PB(v); edge[v].PB(u); } } gen(); FOR(i, 0, N) { int x = label[i]; MessageBoard(i, (val & (1ll << x)) ? 1 : 0); } //generate a tree for each node. }
#include "Ioi.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; static const int MAXN = 10013; static const int MAGIC = 60; static int N, R, V = -1; static vi edge[MAXN]; static int dsu[MAXN]; static ll ans; static vi ord; static vi nodes[MAXN]; static bool vis[MAXN], inside[MAXN]; static int parent[MAXN], label[MAXN]; static int get(int u) { return (u == dsu[u] ? u : dsu[u] = get(dsu[u])); } static bool merge(int u, int v) { u = get(u); v = get(v); if (u == v) { return false; } dsu[u] = v; return true; } static void gen() { //generates all the labels for all the nodes. queue<int> q; q.push(0); while(!q.empty()) { int u = q.front(); q.pop(); label[u] = SZ(nodes[0]); nodes[0].PB(u); vis[u] = true; if (SZ(nodes[0]) == MAGIC) { break; } for (int v : edge[u]) { if (vis[v]) { continue; } parent[v] = u; q.push(v); } } FOR(i, 1, SZ(nodes[0])) { nodes[nodes[0][i]] = nodes[0]; } while(!q.empty()) { int u = q.front(); q.pop(); vis[u] = true; for (int v : nodes[parent[u]]) { inside[v] = true; } nodes[u] = nodes[parent[u]]; FOR(i, 0, SZ(nodes[parent[u]])) { int v = nodes[parent[u]][i]; if (v == parent[u]) continue; int c = 0; for (int x : edge[v]) { if (inside[x]) c++; } if (c == 1) { label[u] = label[v]; nodes[u][i] = u; break; } } for (int v : nodes[parent[u]]) { inside[v] = false; //you just wanna find any leaf, except w } for (int v : edge[u]) { if (vis[v]) { continue; } parent[v] = u; q.push(v); } } } void dfs(int u, int p, int va) { int x = label[u]; if (va) { ans += (1ll << x); } for (int v : edge[u]) { if (v == p || !inside[v]) { continue; } int vv = Move(v); dfs(v, u, vv); Move(u); } } ll Ioi(int n, int m, int e1[], int e2[], int st, int va, int subtask) { N = n; iota(dsu, dsu + N, 0); FOR(i, 0, m) { int u = e1[i], v = e2[i]; if (merge(u, v)) { edge[u].PB(v); edge[v].PB(u); // cerr << "edge " << u << ' ' << v << endl; } } gen(); FOR(i, 0, N) { inside[i] = false; } for (int u : nodes[st]) { inside[u] = true; } dfs(st, N, va); cerr << "Return " << ans << endl; return ans; }

Compilation message (stderr)

Joi.cpp:41:15: warning: 'R' defined but not used [-Wunused-variable]
 static int N, R;
               ^

Ioi.cpp:41:18: warning: 'V' defined but not used [-Wunused-variable]
 static int N, R, V = -1;
                  ^
Ioi.cpp:41:15: warning: 'R' defined but not used [-Wunused-variable]
 static int N, R, V = -1;
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...