#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e4;
static int N, M;
static ll X;
static vector<int> adj[MAXN+10], tree[MAXN+10];
static set<int> group[MAXN+10];
static int dis[MAXN+10], invdis[MAXN+10], par[MAXN+10], col[MAXN+10];
static int cnt=0;
static void makeTree(int now)
{
int i, j;
dis[now]=cnt++;
invdis[dis[now]]=now;
if(dis[now]<60)
{
group[now].insert(now);
col[now]=dis[now];
}
for(int nxt : adj[now])
{
if(dis[nxt]!=-1) continue;
makeTree(nxt);
tree[now].push_back(nxt);
tree[nxt].push_back(now);
par[nxt]=now;
}
}
static int leaf;
static void dfs(int now, int bef, int grp)
{
if(cnt==60) { leaf=now; return; }
cnt++;
for(int nxt : tree[now])
{
if(nxt==bef) continue;
if(!binary_search(group[grp].begin(), group[grp].end(), nxt)) continue;
dfs(nxt, now, grp);
}
}
static void color()
{
int i, j;
set<int> start;
for(i=0; i<N; i++) if(dis[i]<60) start.insert(*group[i].begin());
for(i=0; i<N; i++) if(dis[i]<60) group[i]=start;
for(i=60; i<N; i++)
{
int now=invdis[i];
cnt=1; leaf=0;
dfs(par[now], now, par[now]);
for(int it : group[par[now]]) if(it!=leaf) group[now].insert(it);
col[now]=col[leaf];
group[now].insert(now);
}
}
void Joi(int n, int m, int A[], int B[], ll x, int T)
{
int i, j;
N=n; M=m; X=x;
for(i=0; i<M; i++)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
memset(dis, -1, sizeof(dis));
memset(col, -1, sizeof(col));
makeTree(1);
color();
for(i=0; i<N; i++)
{
if(x&(1ll<<col[i])) MessageBoard(i, 1);
else MessageBoard(i, 0);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e4;
static int N, M, P, V;
static vector<int> adj[MAXN+10], tree[MAXN+10];
static set<int> group[MAXN+10];
static int dis[MAXN+10], invdis[MAXN+10], par[MAXN+10], col[MAXN+10];
static ll ans;
static int cnt=0;
static void makeTree(int now)
{
int i, j;
dis[now]=cnt++;
invdis[dis[now]]=now;
if(dis[now]<60)
{
group[now].insert(now);
col[now]=dis[now];
}
for(int nxt : adj[now])
{
if(dis[nxt]!=-1) continue;
makeTree(nxt);
tree[now].push_back(nxt);
tree[nxt].push_back(now);
par[nxt]=now;
}
}
static int leaf;
static void dfs(int now, int bef, int grp)
{
if(cnt==60) { leaf=now; return; }
cnt++;
for(int nxt : tree[now])
{
if(nxt==bef) continue;
if(!group[grp].count(nxt)) continue;
dfs(nxt, now, grp);
}
}
static void color()
{
int i, j;
set<int> start;
for(i=0; i<N; i++) if(dis[i]<60) start.insert(*group[i].begin());
for(i=0; i<N; i++) if(dis[i]<60) group[i]=start;
for(i=60; i<N; i++)
{
int now=invdis[i];
cnt=1; leaf=0;
dfs(par[now], now, par[now]);
for(int it : group[par[now]]) if(it!=leaf) group[now].insert(it);
col[now]=col[leaf];
group[now].insert(now);
}
}
static void tour(int now, int bef)
{
for(int nxt : tree[now])
{
if(nxt==bef) continue;
if(!binary_search(group[P].begin(), group[P].end(), nxt)) continue;
ans|=(ll)Move(nxt)<<col[nxt];
tour(nxt, now);
ans|=(ll)Move(now)<<col[now];
}
}
ll Ioi(int n, int m, int A[], int B[], int p, int v, int T)
{
int i, j;
N=n; M=m; P=p; V=v;
for(i=0; i<M; i++)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
memset(dis, -1, sizeof(dis));
memset(col, -1, sizeof(col));
makeTree(1);
color();
ans|=(ll)V<<col[P];
tour(P, P);
return ans;
}
Compilation message
Joi.cpp: In function 'void makeTree(int)':
Joi.cpp:21:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
Joi.cpp:21:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Joi.cpp: In function 'void color()':
Joi.cpp:55:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Joi.cpp: In function 'void Joi(int, int, int*, int*, ll, int)':
Joi.cpp:73:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'void makeTree(int)':
Ioi.cpp:21:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
Ioi.cpp:21:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'void color()':
Ioi.cpp:55:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'll Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:85:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3184 KB |
Output is correct |
2 |
Correct |
12 ms |
3696 KB |
Output is correct |
3 |
Correct |
25 ms |
4832 KB |
Output is correct |
4 |
Correct |
10 ms |
3484 KB |
Output is correct |
5 |
Correct |
9 ms |
3472 KB |
Output is correct |
6 |
Correct |
17 ms |
3916 KB |
Output is correct |
7 |
Correct |
24 ms |
4736 KB |
Output is correct |
8 |
Correct |
52 ms |
4648 KB |
Output is correct |
9 |
Correct |
26 ms |
4476 KB |
Output is correct |
10 |
Correct |
12 ms |
3760 KB |
Output is correct |
11 |
Correct |
13 ms |
3884 KB |
Output is correct |
12 |
Correct |
6 ms |
3232 KB |
Output is correct |
13 |
Correct |
22 ms |
4600 KB |
Output is correct |
14 |
Correct |
22 ms |
4472 KB |
Output is correct |
15 |
Correct |
24 ms |
4608 KB |
Output is correct |
16 |
Correct |
24 ms |
4752 KB |
Output is correct |
17 |
Correct |
25 ms |
4472 KB |
Output is correct |
18 |
Correct |
23 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
63184 KB |
Output is correct |
2 |
Correct |
790 ms |
62836 KB |
Output is correct |
3 |
Correct |
796 ms |
63124 KB |
Output is correct |
4 |
Correct |
1202 ms |
61496 KB |
Output is correct |
5 |
Correct |
660 ms |
62448 KB |
Output is correct |
6 |
Correct |
1049 ms |
61936 KB |
Output is correct |
7 |
Correct |
1136 ms |
61788 KB |
Output is correct |
8 |
Correct |
1105 ms |
62168 KB |
Output is correct |
9 |
Correct |
998 ms |
61936 KB |
Output is correct |
10 |
Execution timed out |
3015 ms |
4108 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3312 KB |
Output is correct |
2 |
Correct |
8 ms |
3320 KB |
Output is correct |
3 |
Correct |
8 ms |
3396 KB |
Output is correct |
4 |
Correct |
91 ms |
12332 KB |
Output is correct |
5 |
Correct |
92 ms |
12332 KB |
Output is correct |
6 |
Correct |
92 ms |
12460 KB |
Output is correct |
7 |
Correct |
95 ms |
12400 KB |
Output is correct |
8 |
Correct |
92 ms |
12308 KB |
Output is correct |
9 |
Correct |
554 ms |
62132 KB |
Output is correct |
10 |
Correct |
564 ms |
62160 KB |
Output is correct |
11 |
Correct |
554 ms |
62104 KB |
Output is correct |
12 |
Correct |
6 ms |
3212 KB |
Output is correct |
13 |
Correct |
7 ms |
3320 KB |
Output is correct |
14 |
Correct |
6 ms |
3228 KB |
Output is correct |
15 |
Correct |
6 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
809 ms |
62752 KB |
Output is correct |
2 |
Correct |
800 ms |
63104 KB |
Output is correct |
3 |
Correct |
800 ms |
62844 KB |
Output is correct |
4 |
Correct |
966 ms |
61768 KB |
Output is correct |
5 |
Correct |
660 ms |
62384 KB |
Output is correct |
6 |
Correct |
1097 ms |
61936 KB |
Output is correct |
7 |
Correct |
1097 ms |
61940 KB |
Output is correct |
8 |
Correct |
1138 ms |
62384 KB |
Output is correct |
9 |
Correct |
1121 ms |
61808 KB |
Output is correct |
10 |
Execution timed out |
3036 ms |
4164 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
807 ms |
62940 KB |
Output is correct |
2 |
Correct |
794 ms |
63036 KB |
Output is correct |
3 |
Correct |
794 ms |
62804 KB |
Output is correct |
4 |
Correct |
1031 ms |
61740 KB |
Output is correct |
5 |
Correct |
664 ms |
62420 KB |
Output is correct |
6 |
Correct |
1119 ms |
61940 KB |
Output is correct |
7 |
Correct |
1067 ms |
62072 KB |
Output is correct |
8 |
Correct |
995 ms |
62076 KB |
Output is correct |
9 |
Correct |
1073 ms |
62264 KB |
Output is correct |
10 |
Execution timed out |
3066 ms |
4288 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |