// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Joi.h"
void Joi(int n, int m, int A[], int B[], long long X, int T) {
vector<int> adj[n];
rep(i,m){
int u = A[i], v = B[i];
adj[u].pb(v), adj[v].pb(u);
}
vector<int> cnt(n);
vector<pii> group(n,{-1,-1});
queue<pii> q;
q.push({0,0});
group[0] = {0,0};
cnt[0]++;
int ptr = 1;
while(!q.empty()){
auto [u,c] = q.front();
q.pop();
trav(v,adj[u]){
if(group[v].ff != -1) conts;
int id = c;
if(cnt[c] == 60){
id = ptr++;
}
q.push({v,id});
group[v] = {id,cnt[id]++};
}
}
rep(i,n){
int bit = group[i].ss;
int b = 0;
if(X & (1ll<<bit)) b = 1;
MessageBoard(i,b);
}
}
// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e4 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Ioi.h"
vector<int> adj2[60];
vector<bool> vis(60);
vector<int> actual_nodes(60);
vector<int> depth(60), deepest(60);
set<pii> st;
ll x_val = 0;
void dfs1(int u){
vis[u] = 1;
deepest[u] = depth[u];
trav(v,adj2[u]){
if(vis[v]) conts;
st.insert({u,v});
st.insert({v,u});
depth[v] = depth[u]+1;
dfs1(v);
amax(deepest[u],deepest[v]);
}
}
void dfs2(int u){
vis[u] = 1;
pii best = {-1,-1};
trav(v,adj2[u]){
if(vis[v]) conts;
if(!st.count({u,v})) conts;
pii px = {deepest[v],v};
amax(best,px);
}
trav(v,adj2[u]){
if(vis[v]) conts;
if(v == best.ss) conts;
if(!st.count({u,v})) conts;
int b = Move(actual_nodes[v]);
int bit = v;
if(b) x_val |= (1ll<<bit);
dfs2(v);
Move(actual_nodes[u]);
}
if(best.ss != -1){
int v = best.ss;
int b = Move(actual_nodes[v]);
int bit = v;
if(b) x_val |= (1ll<<bit);
dfs2(v);
Move(actual_nodes[u]);
}
}
long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
vector<int> adj[n];
rep(i,m){
int u = A[i], v = B[i];
adj[u].pb(v), adj[v].pb(u);
}
vector<int> cnt(n);
vector<pii> group(n,{-1,-1});
queue<pii> q;
q.push({0,0});
group[0] = {0,0};
cnt[0]++;
int ptr = 1;
while(!q.empty()){
auto [u,c] = q.front();
q.pop();
trav(v,adj[u]){
if(group[v].ff != -1) conts;
int id = c;
if(cnt[c] == 60){
id = ptr++;
}
q.push({v,id});
group[v] = {id,cnt[id]++};
}
}
rep(i,n){
assert(cnt[i] <= 60);
}
// find closest good group
queue<int> q2;
vector<int> par(n,-1);
q2.push(P);
par[P] = P;
int want = -1;
while(!q2.empty()){
int u = q2.front();
q2.pop();
int c = group[u].ff;
if(cnt[c] == 60){
want = u;
break;
}
trav(v,adj[u]){
if(par[v] == -1){
q2.push(v);
par[v] = u;
}
}
}
assert(want != -1);
int root = group[want].ss;
int root_val = V;
vector<int> path;
int o_want = want;
while(want != P){
path.pb(want);
want = par[want];
}
reverse(all(path));
trav(u,path){
root_val = Move(u);
P = u;
}
want = o_want;
assert(P == want);
int want_col = group[want].ff;
rep(u,n){
if(group[u].ff == want_col){
actual_nodes[group[u].ss] = u;
}
}
rep(u,n){
trav(v,adj[u]){
if(group[u].ff == want_col and group[v].ff == want_col){
int x = group[u].ss;
int y = group[v].ss;
adj2[x].pb(y);
adj2[y].pb(x);
}
}
}
if(root_val) x_val |= (1ll<<root);
dfs1(root);
fill(all(vis),0);
dfs2(root);
return x_val;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
0 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
648 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
772 KB |
Output is correct |
8 |
Correct |
1 ms |
772 KB |
Output is correct |
9 |
Correct |
0 ms |
644 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
1092 KB |
Output is correct |
12 |
Correct |
0 ms |
516 KB |
Output is correct |
13 |
Correct |
0 ms |
772 KB |
Output is correct |
14 |
Correct |
2 ms |
772 KB |
Output is correct |
15 |
Correct |
0 ms |
772 KB |
Output is correct |
16 |
Correct |
1 ms |
748 KB |
Output is correct |
17 |
Correct |
1 ms |
772 KB |
Output is correct |
18 |
Correct |
1 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3656 KB |
Output is correct |
2 |
Correct |
17 ms |
3660 KB |
Output is correct |
3 |
Correct |
19 ms |
3540 KB |
Output is correct |
4 |
Correct |
11 ms |
2892 KB |
Output is correct |
5 |
Correct |
9 ms |
2756 KB |
Output is correct |
6 |
Correct |
10 ms |
2764 KB |
Output is correct |
7 |
Correct |
10 ms |
2708 KB |
Output is correct |
8 |
Correct |
9 ms |
2692 KB |
Output is correct |
9 |
Correct |
10 ms |
2668 KB |
Output is correct |
10 |
Correct |
10 ms |
2880 KB |
Output is correct |
11 |
Correct |
9 ms |
2896 KB |
Output is correct |
12 |
Correct |
10 ms |
2612 KB |
Output is correct |
13 |
Correct |
9 ms |
2620 KB |
Output is correct |
14 |
Correct |
11 ms |
2576 KB |
Output is correct |
15 |
Correct |
11 ms |
2756 KB |
Output is correct |
16 |
Correct |
9 ms |
2904 KB |
Output is correct |
17 |
Correct |
10 ms |
2884 KB |
Output is correct |
18 |
Correct |
10 ms |
2868 KB |
Output is correct |
19 |
Correct |
12 ms |
2844 KB |
Output is correct |
20 |
Correct |
10 ms |
2768 KB |
Output is correct |
21 |
Correct |
9 ms |
2628 KB |
Output is correct |
22 |
Correct |
11 ms |
2756 KB |
Output is correct |
23 |
Correct |
11 ms |
2760 KB |
Output is correct |
24 |
Correct |
11 ms |
2756 KB |
Output is correct |
25 |
Correct |
9 ms |
2764 KB |
Output is correct |
26 |
Correct |
12 ms |
2696 KB |
Output is correct |
27 |
Correct |
9 ms |
2748 KB |
Output is correct |
28 |
Correct |
10 ms |
2760 KB |
Output is correct |
29 |
Correct |
10 ms |
2496 KB |
Output is correct |
30 |
Correct |
11 ms |
2620 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
640 KB |
Output is correct |
33 |
Correct |
1 ms |
772 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
2 ms |
640 KB |
Output is correct |
36 |
Correct |
0 ms |
512 KB |
Output is correct |
37 |
Correct |
0 ms |
572 KB |
Output is correct |
38 |
Correct |
0 ms |
648 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
520 KB |
Output is correct |
41 |
Correct |
0 ms |
640 KB |
Output is correct |
42 |
Correct |
0 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
0 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
1052 KB |
Output is correct |
5 |
Correct |
2 ms |
1056 KB |
Output is correct |
6 |
Correct |
2 ms |
1052 KB |
Output is correct |
7 |
Correct |
2 ms |
1048 KB |
Output is correct |
8 |
Correct |
2 ms |
1064 KB |
Output is correct |
9 |
Correct |
10 ms |
2828 KB |
Output is correct |
10 |
Correct |
8 ms |
2640 KB |
Output is correct |
11 |
Correct |
7 ms |
2632 KB |
Output is correct |
12 |
Correct |
2 ms |
536 KB |
Output is correct |
13 |
Correct |
0 ms |
648 KB |
Output is correct |
14 |
Correct |
0 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3640 KB |
Output is correct |
2 |
Correct |
17 ms |
3676 KB |
Output is correct |
3 |
Correct |
18 ms |
3500 KB |
Output is correct |
4 |
Correct |
12 ms |
2804 KB |
Output is correct |
5 |
Partially correct |
11 ms |
2680 KB |
Partially correct |
6 |
Correct |
9 ms |
2784 KB |
Output is correct |
7 |
Correct |
10 ms |
2660 KB |
Output is correct |
8 |
Correct |
10 ms |
2796 KB |
Output is correct |
9 |
Correct |
11 ms |
2868 KB |
Output is correct |
10 |
Correct |
9 ms |
2908 KB |
Output is correct |
11 |
Correct |
9 ms |
2908 KB |
Output is correct |
12 |
Correct |
9 ms |
2644 KB |
Output is correct |
13 |
Partially correct |
10 ms |
2636 KB |
Partially correct |
14 |
Partially correct |
9 ms |
2660 KB |
Partially correct |
15 |
Partially correct |
11 ms |
2772 KB |
Partially correct |
16 |
Correct |
9 ms |
2780 KB |
Output is correct |
17 |
Correct |
9 ms |
2860 KB |
Output is correct |
18 |
Partially correct |
10 ms |
2920 KB |
Partially correct |
19 |
Correct |
9 ms |
2800 KB |
Output is correct |
20 |
Correct |
8 ms |
2784 KB |
Output is correct |
21 |
Correct |
7 ms |
2652 KB |
Output is correct |
22 |
Correct |
10 ms |
2780 KB |
Output is correct |
23 |
Correct |
11 ms |
2784 KB |
Output is correct |
24 |
Correct |
10 ms |
2784 KB |
Output is correct |
25 |
Correct |
9 ms |
2800 KB |
Output is correct |
26 |
Correct |
10 ms |
2820 KB |
Output is correct |
27 |
Correct |
11 ms |
2780 KB |
Output is correct |
28 |
Correct |
9 ms |
2780 KB |
Output is correct |
29 |
Correct |
9 ms |
2636 KB |
Output is correct |
30 |
Correct |
13 ms |
2624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
3648 KB |
Output is correct |
2 |
Correct |
19 ms |
3660 KB |
Output is correct |
3 |
Correct |
17 ms |
3716 KB |
Output is correct |
4 |
Correct |
10 ms |
2744 KB |
Output is correct |
5 |
Incorrect |
9 ms |
2624 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |