#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], 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].push_back(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;
vector<int> start;
for(i=0; i<N; i++) if(dis[i]<60) start.push_back(group[i][0]);
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].push_back(it);
col[now]=col[leaf];
group[now].push_back(now);
sort(group[now].begin(), group[now].end());
}
}
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], 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].push_back(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;
vector<int> start;
for(i=0; i<N; i++) if(dis[i]<60) start.push_back(group[i][0]);
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].push_back(it);
col[now]=col[leaf];
group[now].push_back(now);
sort(group[now].begin(), group[now].end());
}
}
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:20:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
Joi.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Joi.cpp: In function 'void color()':
Joi.cpp:54: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:20:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
Ioi.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'void color()':
Ioi.cpp:54: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;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2416 KB |
Output is correct |
2 |
Correct |
6 ms |
2416 KB |
Output is correct |
3 |
Correct |
8 ms |
2680 KB |
Output is correct |
4 |
Correct |
6 ms |
2416 KB |
Output is correct |
5 |
Correct |
6 ms |
2416 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
8 ms |
2688 KB |
Output is correct |
8 |
Correct |
8 ms |
2688 KB |
Output is correct |
9 |
Correct |
8 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2540 KB |
Output is correct |
11 |
Correct |
9 ms |
2848 KB |
Output is correct |
12 |
Correct |
6 ms |
2472 KB |
Output is correct |
13 |
Correct |
8 ms |
2764 KB |
Output is correct |
14 |
Correct |
8 ms |
2632 KB |
Output is correct |
15 |
Correct |
8 ms |
2764 KB |
Output is correct |
16 |
Correct |
8 ms |
2560 KB |
Output is correct |
17 |
Correct |
8 ms |
2768 KB |
Output is correct |
18 |
Correct |
8 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
11384 KB |
Output is correct |
2 |
Correct |
144 ms |
11492 KB |
Output is correct |
3 |
Correct |
176 ms |
11348 KB |
Output is correct |
4 |
Correct |
153 ms |
9864 KB |
Output is correct |
5 |
Correct |
125 ms |
10736 KB |
Output is correct |
6 |
Correct |
151 ms |
10416 KB |
Output is correct |
7 |
Correct |
154 ms |
10300 KB |
Output is correct |
8 |
Correct |
152 ms |
10400 KB |
Output is correct |
9 |
Correct |
144 ms |
10680 KB |
Output is correct |
10 |
Execution timed out |
3026 ms |
4508 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2288 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
6 ms |
2544 KB |
Output is correct |
4 |
Correct |
15 ms |
3736 KB |
Output is correct |
5 |
Correct |
14 ms |
3600 KB |
Output is correct |
6 |
Correct |
15 ms |
3728 KB |
Output is correct |
7 |
Correct |
14 ms |
3600 KB |
Output is correct |
8 |
Correct |
15 ms |
3740 KB |
Output is correct |
9 |
Correct |
66 ms |
11112 KB |
Output is correct |
10 |
Correct |
65 ms |
11048 KB |
Output is correct |
11 |
Correct |
66 ms |
11296 KB |
Output is correct |
12 |
Correct |
6 ms |
2416 KB |
Output is correct |
13 |
Correct |
6 ms |
2288 KB |
Output is correct |
14 |
Correct |
6 ms |
2416 KB |
Output is correct |
15 |
Correct |
5 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
11392 KB |
Output is correct |
2 |
Correct |
138 ms |
11392 KB |
Output is correct |
3 |
Correct |
137 ms |
11248 KB |
Output is correct |
4 |
Correct |
124 ms |
10036 KB |
Output is correct |
5 |
Correct |
122 ms |
10684 KB |
Output is correct |
6 |
Correct |
151 ms |
10304 KB |
Output is correct |
7 |
Correct |
153 ms |
10200 KB |
Output is correct |
8 |
Correct |
156 ms |
10328 KB |
Output is correct |
9 |
Correct |
155 ms |
10296 KB |
Output is correct |
10 |
Execution timed out |
3090 ms |
4628 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
11380 KB |
Output is correct |
2 |
Correct |
138 ms |
11296 KB |
Output is correct |
3 |
Correct |
138 ms |
11420 KB |
Output is correct |
4 |
Correct |
134 ms |
9792 KB |
Output is correct |
5 |
Correct |
115 ms |
11072 KB |
Output is correct |
6 |
Correct |
156 ms |
10272 KB |
Output is correct |
7 |
Correct |
159 ms |
10296 KB |
Output is correct |
8 |
Correct |
141 ms |
10492 KB |
Output is correct |
9 |
Correct |
149 ms |
10396 KB |
Output is correct |
10 |
Execution timed out |
3035 ms |
4612 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |