#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
int n,m;
long long x;
int t;
int arr[10000];
int p[10000];
vector<int> adj[10000];
typedef pair<int,int> P;
int dist[10000];
int find(int a) {
return p[a]<0?a:p[a]=find(p[a]);
}
void merge(int a,int b) {
a=find(a);
b=find(b);
if (a==b) {
return;
}
p[b]=a;
}
P longest() {
memset(dist,-1,sizeof(dist));
queue<int> q;
q.push(0);
dist[0]=0;
while (!q.empty()) {
int now=q.front();
q.pop();
for(int i=0;i<adj[now].size();i++) {
int nt=adj[now][i];
if (dist[nt]==-1) {
dist[nt]=dist[now]+1;
q.push(nt);
}
}
}
int pos=0;
for(int i=1;i<n;i++) {
if (dist[i]>dist[pos]) {
pos=i;
}
}
memset(dist,-1,sizeof(dist));
dist[pos]=0;
q.push(pos);
while (!q.empty()) {
int now=q.front();
q.pop();
for(int i=0;i<adj[now].size();i++) {
int nt=adj[now][i];
if (dist[nt]==-1) {
dist[nt]=dist[now]+1;
q.push(nt);
}
}
}
int pos1=0;
for(int i=1;i<n;i++) {
if (dist[i]>dist[pos1]) {
pos1=i;
}
}
return P(pos,dist[pos1]);
}
int f=0;
void dfs0(int v,int d,int prev) {
int now=d%60;
if (x&(1LL<<now)) {
MessageBoard(v,1);
}
else {
MessageBoard(v,0);
}
for(int i=0;i<adj[v].size();i++) {
int nt=adj[v][i];
if (nt==prev) {
continue;
}
//assert(nt==v-1);
dfs0(nt,d+1,v);
}
}
void dfs1(int v,int prev) {
int now=f%60;
if (x&(1LL<<now)) {
MessageBoard(v,1);
}
else {
MessageBoard(v,0);
}
f++;
for(int i=0;i<adj[v].size();i++) {
int nt=adj[v][i];
if (nt==prev) {
continue;
}
dfs1(nt,v);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
n=N;
m=M;
x=X;
t=T;
memset(p,-1,sizeof(p));
for(int i=0;i<m;i++) {
if (find(A[i])!=find(B[i])) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
merge(A[i],B[i]);
}
}
dfs1(0,-1);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int st,val,t;
int p[10000];
vector<int> adj[10000];
int dist[10000];
typedef pair<int,int> P;
int find(int a) {
return p[a]<0?a:p[a]=find(p[a]);
}
void merge(int a,int b) {
a=find(a);
b=find(b);
if (a==b) {
return;
}
p[b]=a;
}
P longest() {
memset(dist,-1,sizeof(dist));
queue<int> q;
q.push(0);
dist[0]=0;
while (!q.empty()) {
int now=q.front();
q.pop();
for(int i=0;i<adj[now].size();i++) {
int nt=adj[now][i];
if (dist[nt]==-1) {
dist[nt]=dist[now]+1;
q.push(nt);
}
}
}
int pos=0;
for(int i=1;i<n;i++) {
if (dist[i]>dist[pos]) {
pos=i;
}
}
memset(dist,-1,sizeof(dist));
dist[pos]=0;
q.push(pos);
while (!q.empty()) {
int now=q.front();
q.pop();
for(int i=0;i<adj[now].size();i++) {
int nt=adj[now][i];
if (dist[nt]==-1) {
dist[nt]=dist[now]+1;
q.push(nt);
}
}
}
int pos1=0;
for(int i=1;i<n;i++) {
if (dist[i]>dist[pos1]) {
pos1=i;
}
}
return P(pos,dist[pos1]);
}
int par[10000];
int dep[10000];
int ind[10000];
int rev[10000];
int sz[10000];
int md[10000];
int f=0;
void dfs(int v,int prev) {
par[v]=prev;
md[v]=dep[v];
sz[v]=1;
ind[v]=f++;
rev[ind[v]]=v;
for(int i=0;i<adj[v].size();i++) {
int nt=adj[v][i];
if (nt!=prev) {
dep[nt]=dep[v]+1;
dfs(nt,v);
md[v]=max(md[v],md[nt]);
sz[v]+=sz[nt];
}
}
}
bool need[10000];
long long chk[60];
void dfs1(int v,int prev) {
chk[ind[v]%60]=val;
for(int i=0;i<adj[v].size();i++) {
int nt=adj[v][i];
if (nt==prev||!need[nt]) {
continue;
}
val=Move(nt);
dfs1(nt,v);
val=Move(v);
}
}
long long Ioi(int N, int M, int A[], int B[], int PP, int V, int T) {
n=N;
m=M;
st=PP;
val=V;
t=T;
memset(p,-1,sizeof(p));
for(int i=0;i<m;i++) {
if (find(A[i])!=find(B[i])) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
merge(A[i],B[i]);
}
}
dfs(0,-1);
int now=st;
int pr=-1;
while (sz[now]<60) {
pr=now;
now=par[now];
}
need[now]=true;
int l=ind[now];
int r=ind[now]+sz[now]-1;
int vst=0;
if (pr==-1) {
vst=l;
}
else {
int ll=ind[pr];
int rr=ind[pr]+sz[pr]-1;
while (rr-ll<59) {
if (ll!=l) {
ll--;
}
else if (rr!=r) {
rr++;
}
}
vst=ll;
}
for(int i=vst;i<vst+60;i++) {
need[rev[i]]=true;
int v=rev[i];
while (v!=now) {
v=par[v];
need[v]=true;
}
}
dfs1(st,-1);
long long ret=0;
for(int i=0;i<60;i++) {
ret+=(chk[i]<<i);
}
return ret;
}
Compilation message
Joi.cpp: In function 'P longest()':
Joi.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0;i<adj[now].size();i++) {
| ~^~~~~~~~~~~~~~~~
Joi.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0;i<adj[now].size();i++) {
| ~^~~~~~~~~~~~~~~~
Joi.cpp: In function 'void dfs0(int, int, int)':
Joi.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i=0;i<adj[v].size();i++) {
| ~^~~~~~~~~~~~~~
Joi.cpp: In function 'void dfs1(int, int)':
Joi.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0;i<adj[v].size();i++) {
| ~^~~~~~~~~~~~~~
Ioi.cpp: In function 'P longest()':
Ioi.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0;i<adj[now].size();i++) {
| ~^~~~~~~~~~~~~~~~
Ioi.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=0;i<adj[now].size();i++) {
| ~^~~~~~~~~~~~~~~~
Ioi.cpp: In function 'void dfs(int, int)':
Ioi.cpp:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=0;i<adj[v].size();i++) {
| ~^~~~~~~~~~~~~~
Ioi.cpp: In function 'void dfs1(int, int)':
Ioi.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0;i<adj[v].size();i++) {
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1288 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1284 KB |
Output is correct |
4 |
Correct |
1 ms |
1288 KB |
Output is correct |
5 |
Correct |
1 ms |
1288 KB |
Output is correct |
6 |
Correct |
0 ms |
1276 KB |
Output is correct |
7 |
Correct |
1 ms |
1296 KB |
Output is correct |
8 |
Correct |
1 ms |
1292 KB |
Output is correct |
9 |
Correct |
2 ms |
1284 KB |
Output is correct |
10 |
Correct |
0 ms |
1288 KB |
Output is correct |
11 |
Correct |
3 ms |
1464 KB |
Output is correct |
12 |
Correct |
0 ms |
1280 KB |
Output is correct |
13 |
Correct |
2 ms |
1284 KB |
Output is correct |
14 |
Correct |
2 ms |
1284 KB |
Output is correct |
15 |
Correct |
2 ms |
1280 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
1284 KB |
Output is correct |
18 |
Correct |
1 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3412 KB |
Output is correct |
2 |
Correct |
19 ms |
3484 KB |
Output is correct |
3 |
Correct |
20 ms |
3356 KB |
Output is correct |
4 |
Correct |
12 ms |
2880 KB |
Output is correct |
5 |
Correct |
12 ms |
3392 KB |
Output is correct |
6 |
Correct |
12 ms |
3140 KB |
Output is correct |
7 |
Correct |
15 ms |
3272 KB |
Output is correct |
8 |
Correct |
13 ms |
3260 KB |
Output is correct |
9 |
Correct |
15 ms |
3276 KB |
Output is correct |
10 |
Correct |
14 ms |
2884 KB |
Output is correct |
11 |
Correct |
11 ms |
2944 KB |
Output is correct |
12 |
Correct |
11 ms |
2680 KB |
Output is correct |
13 |
Correct |
11 ms |
2732 KB |
Output is correct |
14 |
Correct |
12 ms |
2832 KB |
Output is correct |
15 |
Correct |
12 ms |
2756 KB |
Output is correct |
16 |
Correct |
12 ms |
2756 KB |
Output is correct |
17 |
Correct |
12 ms |
2768 KB |
Output is correct |
18 |
Correct |
15 ms |
2844 KB |
Output is correct |
19 |
Correct |
14 ms |
2728 KB |
Output is correct |
20 |
Correct |
11 ms |
3400 KB |
Output is correct |
21 |
Correct |
11 ms |
3400 KB |
Output is correct |
22 |
Correct |
12 ms |
3140 KB |
Output is correct |
23 |
Correct |
12 ms |
3288 KB |
Output is correct |
24 |
Correct |
13 ms |
3172 KB |
Output is correct |
25 |
Correct |
13 ms |
3112 KB |
Output is correct |
26 |
Correct |
16 ms |
3268 KB |
Output is correct |
27 |
Correct |
13 ms |
3232 KB |
Output is correct |
28 |
Correct |
14 ms |
3400 KB |
Output is correct |
29 |
Correct |
13 ms |
3120 KB |
Output is correct |
30 |
Correct |
12 ms |
3168 KB |
Output is correct |
31 |
Correct |
1 ms |
1288 KB |
Output is correct |
32 |
Correct |
2 ms |
1280 KB |
Output is correct |
33 |
Correct |
2 ms |
1296 KB |
Output is correct |
34 |
Correct |
2 ms |
1288 KB |
Output is correct |
35 |
Correct |
2 ms |
1288 KB |
Output is correct |
36 |
Correct |
2 ms |
1280 KB |
Output is correct |
37 |
Correct |
1 ms |
1280 KB |
Output is correct |
38 |
Correct |
1 ms |
1288 KB |
Output is correct |
39 |
Correct |
2 ms |
1288 KB |
Output is correct |
40 |
Correct |
1 ms |
1280 KB |
Output is correct |
41 |
Correct |
1 ms |
1280 KB |
Output is correct |
42 |
Correct |
1 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
1 ms |
1292 KB |
Output is correct |
4 |
Correct |
2 ms |
1696 KB |
Output is correct |
5 |
Correct |
3 ms |
1700 KB |
Output is correct |
6 |
Correct |
2 ms |
1696 KB |
Output is correct |
7 |
Correct |
3 ms |
1700 KB |
Output is correct |
8 |
Correct |
2 ms |
1700 KB |
Output is correct |
9 |
Correct |
10 ms |
3932 KB |
Output is correct |
10 |
Correct |
11 ms |
4016 KB |
Output is correct |
11 |
Correct |
10 ms |
4048 KB |
Output is correct |
12 |
Correct |
1 ms |
1288 KB |
Output is correct |
13 |
Correct |
1 ms |
1292 KB |
Output is correct |
14 |
Correct |
2 ms |
1280 KB |
Output is correct |
15 |
Correct |
2 ms |
1288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3404 KB |
Output is correct |
2 |
Partially correct |
20 ms |
3396 KB |
Partially correct |
3 |
Correct |
20 ms |
3420 KB |
Output is correct |
4 |
Correct |
13 ms |
2788 KB |
Output is correct |
5 |
Correct |
12 ms |
3776 KB |
Output is correct |
6 |
Correct |
12 ms |
3276 KB |
Output is correct |
7 |
Correct |
12 ms |
3268 KB |
Output is correct |
8 |
Correct |
13 ms |
3160 KB |
Output is correct |
9 |
Correct |
12 ms |
3220 KB |
Output is correct |
10 |
Correct |
10 ms |
2884 KB |
Output is correct |
11 |
Correct |
12 ms |
2892 KB |
Output is correct |
12 |
Correct |
12 ms |
2708 KB |
Output is correct |
13 |
Correct |
11 ms |
2668 KB |
Output is correct |
14 |
Partially correct |
11 ms |
2804 KB |
Partially correct |
15 |
Partially correct |
12 ms |
2872 KB |
Partially correct |
16 |
Partially correct |
12 ms |
2764 KB |
Partially correct |
17 |
Correct |
12 ms |
2768 KB |
Output is correct |
18 |
Correct |
13 ms |
2748 KB |
Output is correct |
19 |
Correct |
13 ms |
2760 KB |
Output is correct |
20 |
Incorrect |
12 ms |
3392 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3396 KB |
Output is correct |
2 |
Incorrect |
20 ms |
3508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |