#include <bits/stdc++.h>
#include "Joi.h"
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#else
#define er(args ...) 0
#endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 60, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
vector<int> adj[maxn], adj2[maxn];
int vl[maxn], par[maxn], h[maxn];
bool vis[maxn], bt[maxn], spe[maxn];
ll ans, X;
void dfs(int r, int& k, int p){
if(k){
vl[r] = k--;
spe[r] = true;
} else vl[r] = h[r]%lg;
bt[r] = X>>vl[r]&1ll;
vis[r] = true;
par[r] = p;
for(int c: adj[r]) if(!vis[c]){
h[c] = h[r] + 1;
dfs(c, k, r);
if(spe[r] && spe[c]){
adj2[r].pb(c);
adj2[c].pb(r);
}
}
}
void Joi(int n, int m, int a[], int b[], ll x, int T) { X = x;
rep(i,0,m){
adj[a[i]].pb(b[i]), adj[b[i]].pb(a[i]);
}
int tmp = lg;
dfs(0, tmp, -1);
vl[0] = 0, bt[0] = X&1ll;
rep(i,0,n) MessageBoard(i, bt[i]);
return;
}
#include <bits/stdc++.h>
#include "Ioi.h"
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#else
#define er(args ...) 0
#endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 60, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
vector<int> adj[maxn], adj2[maxn];
int vl[maxn], par[maxn], h[maxn];
bool vis[maxn], spe[maxn];
ll ans;
void dfs(int r, int& k, int p){
if(k){
vl[r] = k--;
spe[r] = true;
} else vl[r] = h[r]%lg;
vis[r] = true;
par[r] = p;
for(int c: adj[r]) if(!vis[c]){
h[c] = h[r] + 1;
dfs(c, k, r);
if(spe[r] && spe[c]){
adj2[r].pb(c);
adj2[c].pb(r);
}
}
}
int cnt;
void dfs2(int r, int p, bool cr){
if(!cnt) return;
cnt--;
if(cr) ans |= 1ll<<vl[r];
for(int c: adj2[r]) if(c - p) {
dfs2(c, r, Move(c));
if(!cnt) return;
Move(r);
}
}
ll Ioi(int n, int m, int a[], int b[], int x, int cr, int T) {
rep(i,0,m){
adj[a[i]].pb(b[i]), adj[b[i]].pb(a[i]);
}
int tmp = lg;
dfs(0, tmp, -1);
vl[0] = 0;
cnt = lg;
if(spe[x]){
dfs2(x, -1, cr);
} else{
while(par[x] + 1 && cnt){
if(cr) ans |= 1ll<<vl[x];
cr = Move(par[x]), x = par[x];
cnt--;
}
if(cnt) cnt = lg, dfs2(0, -1, cr);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28948 KB |
Output is correct |
2 |
Correct |
15 ms |
28952 KB |
Output is correct |
3 |
Correct |
14 ms |
28968 KB |
Output is correct |
4 |
Correct |
14 ms |
28968 KB |
Output is correct |
5 |
Correct |
16 ms |
28976 KB |
Output is correct |
6 |
Correct |
17 ms |
28972 KB |
Output is correct |
7 |
Correct |
15 ms |
28944 KB |
Output is correct |
8 |
Correct |
14 ms |
28972 KB |
Output is correct |
9 |
Correct |
15 ms |
28964 KB |
Output is correct |
10 |
Correct |
17 ms |
28996 KB |
Output is correct |
11 |
Correct |
17 ms |
29300 KB |
Output is correct |
12 |
Correct |
14 ms |
28956 KB |
Output is correct |
13 |
Correct |
15 ms |
29016 KB |
Output is correct |
14 |
Correct |
17 ms |
29048 KB |
Output is correct |
15 |
Correct |
19 ms |
28996 KB |
Output is correct |
16 |
Correct |
16 ms |
28964 KB |
Output is correct |
17 |
Correct |
15 ms |
28972 KB |
Output is correct |
18 |
Correct |
15 ms |
28972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
32772 KB |
Output is correct |
2 |
Correct |
35 ms |
32796 KB |
Output is correct |
3 |
Correct |
35 ms |
32812 KB |
Output is correct |
4 |
Correct |
26 ms |
30788 KB |
Output is correct |
5 |
Correct |
29 ms |
31760 KB |
Output is correct |
6 |
Correct |
27 ms |
31320 KB |
Output is correct |
7 |
Correct |
27 ms |
31420 KB |
Output is correct |
8 |
Correct |
28 ms |
31624 KB |
Output is correct |
9 |
Correct |
27 ms |
31560 KB |
Output is correct |
10 |
Correct |
25 ms |
30796 KB |
Output is correct |
11 |
Correct |
25 ms |
30892 KB |
Output is correct |
12 |
Correct |
24 ms |
30492 KB |
Output is correct |
13 |
Correct |
27 ms |
30528 KB |
Output is correct |
14 |
Correct |
26 ms |
30684 KB |
Output is correct |
15 |
Correct |
24 ms |
30792 KB |
Output is correct |
16 |
Correct |
24 ms |
30828 KB |
Output is correct |
17 |
Correct |
26 ms |
30740 KB |
Output is correct |
18 |
Correct |
26 ms |
30796 KB |
Output is correct |
19 |
Correct |
26 ms |
30792 KB |
Output is correct |
20 |
Correct |
24 ms |
31728 KB |
Output is correct |
21 |
Correct |
24 ms |
31696 KB |
Output is correct |
22 |
Correct |
27 ms |
31144 KB |
Output is correct |
23 |
Correct |
27 ms |
31600 KB |
Output is correct |
24 |
Correct |
27 ms |
31300 KB |
Output is correct |
25 |
Correct |
26 ms |
31412 KB |
Output is correct |
26 |
Correct |
27 ms |
31524 KB |
Output is correct |
27 |
Correct |
26 ms |
31532 KB |
Output is correct |
28 |
Correct |
30 ms |
31492 KB |
Output is correct |
29 |
Correct |
25 ms |
31228 KB |
Output is correct |
30 |
Correct |
26 ms |
31304 KB |
Output is correct |
31 |
Correct |
15 ms |
28968 KB |
Output is correct |
32 |
Correct |
15 ms |
28960 KB |
Output is correct |
33 |
Correct |
14 ms |
28948 KB |
Output is correct |
34 |
Correct |
14 ms |
28968 KB |
Output is correct |
35 |
Correct |
18 ms |
28960 KB |
Output is correct |
36 |
Correct |
16 ms |
29016 KB |
Output is correct |
37 |
Correct |
14 ms |
28976 KB |
Output is correct |
38 |
Correct |
14 ms |
28968 KB |
Output is correct |
39 |
Correct |
17 ms |
28908 KB |
Output is correct |
40 |
Correct |
18 ms |
28884 KB |
Output is correct |
41 |
Correct |
16 ms |
28944 KB |
Output is correct |
42 |
Correct |
15 ms |
28968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28900 KB |
Output is correct |
2 |
Correct |
15 ms |
28968 KB |
Output is correct |
3 |
Incorrect |
15 ms |
28964 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
32816 KB |
Output is correct |
2 |
Correct |
36 ms |
32852 KB |
Output is correct |
3 |
Correct |
36 ms |
32784 KB |
Output is correct |
4 |
Correct |
30 ms |
30776 KB |
Output is correct |
5 |
Correct |
26 ms |
31996 KB |
Output is correct |
6 |
Partially correct |
26 ms |
31548 KB |
Partially correct |
7 |
Correct |
31 ms |
31548 KB |
Output is correct |
8 |
Correct |
34 ms |
31064 KB |
Output is correct |
9 |
Correct |
35 ms |
31136 KB |
Output is correct |
10 |
Correct |
25 ms |
30864 KB |
Output is correct |
11 |
Correct |
26 ms |
30788 KB |
Output is correct |
12 |
Correct |
24 ms |
30492 KB |
Output is correct |
13 |
Partially correct |
25 ms |
30548 KB |
Partially correct |
14 |
Partially correct |
25 ms |
30732 KB |
Partially correct |
15 |
Correct |
33 ms |
30832 KB |
Output is correct |
16 |
Correct |
25 ms |
30764 KB |
Output is correct |
17 |
Correct |
27 ms |
30768 KB |
Output is correct |
18 |
Partially correct |
27 ms |
30768 KB |
Partially correct |
19 |
Partially correct |
26 ms |
30788 KB |
Partially correct |
20 |
Correct |
24 ms |
31712 KB |
Output is correct |
21 |
Correct |
30 ms |
31676 KB |
Output is correct |
22 |
Correct |
25 ms |
31416 KB |
Output is correct |
23 |
Correct |
25 ms |
31280 KB |
Output is correct |
24 |
Correct |
26 ms |
31344 KB |
Output is correct |
25 |
Correct |
26 ms |
31540 KB |
Output is correct |
26 |
Correct |
25 ms |
31416 KB |
Output is correct |
27 |
Correct |
27 ms |
31672 KB |
Output is correct |
28 |
Correct |
26 ms |
31212 KB |
Output is correct |
29 |
Correct |
24 ms |
31288 KB |
Output is correct |
30 |
Correct |
27 ms |
31412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
32844 KB |
Output is correct |
2 |
Correct |
35 ms |
32808 KB |
Output is correct |
3 |
Correct |
41 ms |
32812 KB |
Output is correct |
4 |
Correct |
31 ms |
30748 KB |
Output is correct |
5 |
Correct |
28 ms |
32320 KB |
Output is correct |
6 |
Correct |
26 ms |
31348 KB |
Output is correct |
7 |
Correct |
28 ms |
31344 KB |
Output is correct |
8 |
Correct |
30 ms |
31564 KB |
Output is correct |
9 |
Correct |
28 ms |
31352 KB |
Output is correct |
10 |
Correct |
29 ms |
30724 KB |
Output is correct |
11 |
Correct |
26 ms |
30800 KB |
Output is correct |
12 |
Correct |
24 ms |
30496 KB |
Output is correct |
13 |
Incorrect |
24 ms |
30568 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |