#include "Joi.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
const int C = 60;
static vi g[N];
static int deg[N];
static int color[N];
static int f[N];
static int get(int k) {
return k == f[k] ? k : f[k] = get(f[k]);
}
static int n;
void Joi(int N, int M, int A[], int B[], long long X, int T) {
n = N;
for (int i = 0;i < n;++i)
f[i] = i,color[i] = -1;
for (int i = 0;i < M;++i) {
if (get(A[i]) == get(B[i]))
continue;
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
f[get(A[i])] = get(B[i]);
}
queue < int > Q;
Q.push(0);
set < int > nodes;
nodes.insert(0);
color[0] = 0;
int shit = 0;
vector < set < int > > vv;
while (!Q.empty()) {
int node = Q.front();
Q.pop();
for (auto u : g[node])
if (color[u] == -1) {
if (nodes.size() < C)
++deg[node],++deg[u],color[u] = ++shit,nodes.insert(u),Q.push(u);
else {
vv.pb(nodes);
int cl = -1;
for (auto v : nodes)
if (deg[v] == 1) {
nodes.erase(v);
--deg[v];
for (auto w : g[v])
if (deg[w] > 0)
--deg[w];
cl = color[v];
break;
}
color[u] = cl;
nodes.insert(u);
}
}
}
vv.pb(nodes);
for (int i = 0;i < n;++i)
MessageBoard(i,(X >> color[i]) & 1);
}
#include "Ioi.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
const int C = 60;
static vi g[N];
static int deg[N];
static int color[N];
static int n;
static int f[N];
static int get(int k) {
return k == f[k] ? k : f[k] = get(f[k]);
}
static int was[N];
static ll answer;
static void dfs(int node,int prev) {
if (prev != -1) {
answer += Move(node) * (1ll << color[node]);
}
for (auto it : g[node])
if (it != prev && was[it]) {
dfs(it,node);
Move(node);
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
n = N;
for (int i = 0;i < n;++i)
f[i] = i,color[i] = -1;
for (int i = 0;i < M;++i) {
if (get(A[i]) == get(B[i]))
continue;
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
f[get(A[i])] = get(B[i]);
}
queue < int > Q;
Q.push(0);
set < int > nodes;
nodes.insert(0);
color[0] = 0;
int shit = 0;
vector < set < int > > vv;
while (!Q.empty()) {
int node = Q.front();
Q.pop();
for (auto u : g[node])
if (color[u] == -1) {
++deg[node];
++deg[u];
if (nodes.size() < C)
color[u] = ++shit,nodes.insert(u),Q.push(u);
else {
vv.pb(nodes);
int cl = -1;
for (auto v : nodes)
if (deg[v] == 1 && u != node) {
nodes.erase(v);
--deg[v];
for (auto w : g[v])
if (deg[w] > 0)
--deg[w];
cl = color[v];
break;
}
color[u] = cl;
nodes.insert(u);
}
}
}
vv.pb(nodes);
for (auto ss : vv)
if (ss.count(P)) {
for (auto it : ss)
was[it] = 1;
break;
}
dfs(P,-1);
answer += V * (1ll << color[P]);
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
47964 KB |
Output is correct |
2 |
Correct |
41 ms |
48388 KB |
Output is correct |
3 |
Incorrect |
48 ms |
48728 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
50712 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
50824 KB |
Output is correct |
2 |
Correct |
44 ms |
50824 KB |
Output is correct |
3 |
Incorrect |
40 ms |
50824 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
50824 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
50824 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |