#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 vector<int> adj[MAXN+10], tree[MAXN+10];
static int num[MAXN+10], cnt=0;
static int par[MAXN+10], deg[MAXN+10], col[MAXN+10];
static bool live[MAXN+10];
static void dfs1(int now)
{
num[now]=cnt++;
if(num[now]<60)
{
live[now]=true;
col[now]=num[now];
}
for(int nxt : adj[now])
{
if(num[nxt]!=-1) continue;
dfs1(nxt);
if(num[now]<60 && num[nxt]<60) deg[now]++, deg[nxt]++;
tree[now].push_back(nxt);
tree[nxt].push_back(now);
par[nxt]=now;
}
}
static bool vis[MAXN+10];
static set<int> S;
static void dfs2(int now)
{
vis[now]=true;
int leaf;
vector<int> V;
if(num[now]>=60)
{
for(auto it : S) if(it!=par[now]) { leaf=it; break; }
S.erase(leaf);
live[leaf]=false; col[now]=col[leaf];
for(int nxt : tree[leaf])
{
if(!live[nxt]) continue;
V.push_back(nxt);
deg[leaf]--;
deg[nxt]--;
if(deg[nxt]==1) S.insert(nxt);
}
deg[par[now]]++;
deg[now]++;
S.insert(now);
}
for(int nxt : tree[now])
{
if(vis[nxt]) continue;
dfs2(nxt);
}
if(num[now]>=60)
{
deg[par[now]]--;
deg[now]--;
S.erase(now);
S.insert(leaf);
live[leaf]=true;
for(int it : V)
{
if(deg[it]==1) S.erase(it);
deg[leaf]++; deg[it]++;
}
}
}
static void makeTree(int A[], int B[])
{
int i, j;
for(i=0; i<M; i++)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
for(i=0; i<N; i++) sort(adj[i].begin(), adj[i].end());
memset(num, -1, sizeof(num));
dfs1(0);
for(i=0; i<N; i++) if(deg[i]==1) S.insert(i);
dfs2(0);
}
void Joi(int n, int m, int A[], int B[], ll X, int T)
{
int i, j;
N=n; M=m;
makeTree(A, B);
for(i=0; i<N; i++)
{
if((1ll<<col[i])&X) 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;
static vector<int> adj[MAXN+10], tree[MAXN+10];
static int num[MAXN+10], cnt=0;
static int par[MAXN+10], deg[MAXN+10], col[MAXN+10];
static bool live[MAXN+10], togo[MAXN+10];
static ll ans;
static void dfs1(int now)
{
num[now]=cnt++;
if(num[now]<60)
{
live[now]=true;
col[now]=num[now];
}
for(int nxt : adj[now])
{
if(num[nxt]!=-1) continue;
dfs1(nxt);
if(num[now]<60 && num[nxt]<60) deg[now]++, deg[nxt]++;
tree[now].push_back(nxt);
tree[nxt].push_back(now);
par[nxt]=now;
}
}
static bool vis[MAXN+10];
static set<int> S;
static void dfs2(int now)
{
vis[now]=true;
int leaf;
vector<int> V;
if(num[now]>=60)
{
for(auto it : S) if(it!=par[now]) { leaf=it; break; }
S.erase(leaf);
live[leaf]=false; col[now]=col[leaf];
for(int nxt : tree[leaf])
{
if(!live[nxt]) continue;
V.push_back(nxt);
deg[leaf]--;
deg[nxt]--;
if(deg[nxt]==1) S.insert(nxt);
}
deg[par[now]]++;
deg[now]++;
S.insert(now);
}
if(now==P)
{
int i, j;
for(i=0; i<N; i++) togo[i]=live[i];
}
for(int nxt : tree[now])
{
if(vis[nxt]) continue;
dfs2(nxt);
}
if(num[now]>=60)
{
deg[par[now]]--;
deg[now]--;
S.erase(now);
S.insert(leaf);
live[leaf]=true;
for(int it : V)
{
if(deg[it]==1) S.erase(it);
deg[leaf]++; deg[it]++;
}
}
}
static void makeTree(int A[], int B[])
{
int i, j;
for(i=0; i<M; i++)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
for(i=0; i<N; i++) sort(adj[i].begin(), adj[i].end());
memset(num, -1, sizeof(num));
dfs1(0);
for(i=0; i<N; i++) if(deg[i]==1) S.insert(i);
dfs2(0);
}
static void dfs3(int now)
{
togo[now]=false;
for(int nxt : tree[now])
{
if(!togo[nxt]) continue;
ans|=(ll)Move(nxt)<<col[nxt];
dfs3(nxt);
ans|=(ll)Move(now)<<col[now];
}
}
ll Ioi(int n, int m, int A[], int B[], int p, int V, int T)
{
N=n; M=m; P=p;
makeTree(A, B);
int i, j;
//for(i=0; i<N; i++) printf("%d : %d\n", i, col[i]);
dfs3(P);
return ans;
}
Compilation message
Joi.cpp: In function 'void makeTree(int*, int*)':
Joi.cpp:88:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Joi.cpp: In function 'void Joi(int, int, int*, int*, ll, int)':
Joi.cpp:105:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'void dfs2(int)':
Ioi.cpp:68:16: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
Ioi.cpp: In function 'void makeTree(int*, int*)':
Ioi.cpp:95: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:126:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
Ioi.cpp:126:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1776 KB |
Output is correct |
2 |
Incorrect |
5 ms |
2056 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
5940 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1904 KB |
Output is correct |
2 |
Correct |
5 ms |
1908 KB |
Output is correct |
3 |
Incorrect |
5 ms |
1912 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
5972 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
5932 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |