#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
struct node{
int idx = -1, visited = 0, val=0, before;
vector<int> adj;
} nodes[200069];
vector<int> BinaryConvert(long long X){
vector<int> res;
while(X > 0){
res.push_back(X % 2);
X/=2;
}
while(res.size()<60) res.push_back(0);
return res;
}
int id=0; vector<int> bit;
void dfs(int idBefore, int idNow){
node now= nodes[idNow];
if(now.visited == 1) return;
nodes[idNow].visited = 1;
nodes[idNow].idx = id++;
nodes[idNow].val = bit[nodes[idNow].idx % 60];
// cout<<"Message "<<nodes[idNow].idx<< " : "<<nodes[idNow].val<<endl;
MessageBoard(idNow, nodes[idNow].val);
nodes[idNow].before= idBefore;
for(int i=0;i<nodes[idNow].adj.size();i++){
dfs(idNow, nodes[idNow].adj[i]);
}
}
int par[200069];
int findParent(int x){
if(x==par[x]) return x;
return findParent(par[x]);
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
bit = BinaryConvert(X);
for(int i=0;i<N;i++) par[i]=i;
for(int i=0;i<M;i++){
if(findParent(A[i])!=findParent(B[i])){
// cout<<A[i]<<" - "<<B[i]<<endl;
nodes[A[i]].adj.push_back(B[i]);
nodes[B[i]].adj.push_back(A[i]);
par[findParent(B[i])] = findParent(A[i]);
}
}
//DFS dulu ges di node 0
dfs(-1,0);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
struct node2{
int idx = -1, visited = 0, val, before=-1, counted = 0;
vector<int> adj;
} nodes2[200069];
int id2=0, bit2[60], countt2=0;
void dfs2(int idBefore, int idNow){
if(nodes2[idNow].visited) return;
nodes2[idNow].visited=1;
nodes2[idNow].idx = id2++;
nodes2[idNow].before= idBefore;
for(int i=0;i<nodes2[idNow].adj.size();i++){
dfs2(idNow, nodes2[idNow].adj[i]);
}
}
int tt=0;
void solveDFS(int idNow, int bitInside){
node2 now = nodes2[idNow];
// cout<<now.idx<<endl;
// cout<<"track count: "<<countt2<<"and now.before "<<now.before<<endl;
if(!nodes2[idNow].counted){
if(tt==3) if(bit2[nodes2[idNow].idx %60] != -1) return;
if(bit2[now.idx % 60] == -1) countt2++;
bit2[now.idx % 60] = bitInside;
// cout<<now.idx<<" "<<bit2[idNow]<<endl;
nodes2[idNow].counted = 1;
for(int i=0;i<now.adj.size();i++){
if (now.adj[i]==now.before) continue;
if(!nodes2[now.adj[i]].counted) {
if(tt==3) if(bit2[nodes2[now.adj[i]].idx %60] != -1) continue;
solveDFS(now.adj[i], Move(now.adj[i]));
if(countt2<60) Move(idNow);
else return;
}
}
//kalau uda cek semua anak"nya ya pindah ke ibunya diatas 1
// if(idNow==5) cout<<"before 5"<<now.before<<endl;
if(now.before != -1){
if(!nodes2[now.before].counted && countt2<60){
// cout<<"use here";
solveDFS(now.before, Move(now.before));
}
}
}
}
int par2[200069];
int findParent2(int x){
if(x==par2[x]) return x;
return findParent2(par2[x]);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
for(int i=0;i<N;i++) par2[i]=i;
for(int i=0;i<M;i++){
if(findParent2(A[i])!=findParent2(B[i])){
nodes2[A[i]].adj.push_back(B[i]);
nodes2[B[i]].adj.push_back(A[i]);
par2[findParent2(B[i])] = findParent2(A[i]);
}
}
//DFS dulu ges di node 0
dfs2(-1,0);
//Solve
tt=T;
memset(bit2, -1, sizeof(bit2));
solveDFS(P,V);
//Convert to decimal
long long key = 1, res= 0;
for(int i=0;i<60;i++){
res += bit2[i] * key;
key*=2;
}
return res;
}
Compilation message
Joi.cpp: In function 'void dfs(int, int)':
Joi.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=0;i<nodes[idNow].adj.size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'void dfs2(int, int)':
Ioi.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i=0;i<nodes2[idNow].adj.size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'void solveDFS(int, int)':
Ioi.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<now.adj.size();i++){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
17944 KB |
Output is correct |
2 |
Correct |
9 ms |
17944 KB |
Output is correct |
3 |
Correct |
9 ms |
17948 KB |
Output is correct |
4 |
Correct |
9 ms |
17984 KB |
Output is correct |
5 |
Correct |
10 ms |
17876 KB |
Output is correct |
6 |
Correct |
9 ms |
17944 KB |
Output is correct |
7 |
Correct |
11 ms |
17940 KB |
Output is correct |
8 |
Correct |
10 ms |
17936 KB |
Output is correct |
9 |
Correct |
11 ms |
17892 KB |
Output is correct |
10 |
Correct |
9 ms |
17936 KB |
Output is correct |
11 |
Correct |
13 ms |
18096 KB |
Output is correct |
12 |
Correct |
9 ms |
17936 KB |
Output is correct |
13 |
Correct |
10 ms |
17944 KB |
Output is correct |
14 |
Correct |
10 ms |
17948 KB |
Output is correct |
15 |
Correct |
10 ms |
17948 KB |
Output is correct |
16 |
Correct |
10 ms |
17948 KB |
Output is correct |
17 |
Correct |
9 ms |
17936 KB |
Output is correct |
18 |
Correct |
11 ms |
17940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
19816 KB |
Output is correct |
2 |
Correct |
153 ms |
19900 KB |
Output is correct |
3 |
Correct |
150 ms |
19916 KB |
Output is correct |
4 |
Correct |
25 ms |
19292 KB |
Output is correct |
5 |
Correct |
26 ms |
20340 KB |
Output is correct |
6 |
Correct |
23 ms |
19940 KB |
Output is correct |
7 |
Correct |
25 ms |
19952 KB |
Output is correct |
8 |
Correct |
22 ms |
20064 KB |
Output is correct |
9 |
Correct |
23 ms |
20292 KB |
Output is correct |
10 |
Correct |
287 ms |
19396 KB |
Output is correct |
11 |
Correct |
260 ms |
19512 KB |
Output is correct |
12 |
Correct |
22 ms |
19268 KB |
Output is correct |
13 |
Correct |
22 ms |
19228 KB |
Output is correct |
14 |
Correct |
23 ms |
19276 KB |
Output is correct |
15 |
Correct |
30 ms |
19300 KB |
Output is correct |
16 |
Correct |
31 ms |
19284 KB |
Output is correct |
17 |
Correct |
23 ms |
19412 KB |
Output is correct |
18 |
Correct |
26 ms |
19416 KB |
Output is correct |
19 |
Correct |
26 ms |
19284 KB |
Output is correct |
20 |
Correct |
19 ms |
20264 KB |
Output is correct |
21 |
Correct |
19 ms |
20308 KB |
Output is correct |
22 |
Correct |
22 ms |
19800 KB |
Output is correct |
23 |
Correct |
22 ms |
20060 KB |
Output is correct |
24 |
Correct |
20 ms |
19904 KB |
Output is correct |
25 |
Correct |
27 ms |
19984 KB |
Output is correct |
26 |
Correct |
23 ms |
20188 KB |
Output is correct |
27 |
Correct |
23 ms |
20028 KB |
Output is correct |
28 |
Correct |
23 ms |
20188 KB |
Output is correct |
29 |
Correct |
20 ms |
19904 KB |
Output is correct |
30 |
Correct |
22 ms |
19964 KB |
Output is correct |
31 |
Correct |
9 ms |
17944 KB |
Output is correct |
32 |
Correct |
10 ms |
18000 KB |
Output is correct |
33 |
Correct |
11 ms |
17976 KB |
Output is correct |
34 |
Correct |
10 ms |
17948 KB |
Output is correct |
35 |
Correct |
10 ms |
17936 KB |
Output is correct |
36 |
Correct |
10 ms |
17936 KB |
Output is correct |
37 |
Correct |
11 ms |
17932 KB |
Output is correct |
38 |
Correct |
10 ms |
17932 KB |
Output is correct |
39 |
Correct |
10 ms |
17944 KB |
Output is correct |
40 |
Correct |
9 ms |
17944 KB |
Output is correct |
41 |
Correct |
11 ms |
17916 KB |
Output is correct |
42 |
Correct |
9 ms |
17940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
17868 KB |
Output is correct |
2 |
Correct |
9 ms |
17968 KB |
Output is correct |
3 |
Correct |
10 ms |
17936 KB |
Output is correct |
4 |
Correct |
11 ms |
18360 KB |
Output is correct |
5 |
Correct |
10 ms |
18348 KB |
Output is correct |
6 |
Correct |
11 ms |
18356 KB |
Output is correct |
7 |
Correct |
12 ms |
18352 KB |
Output is correct |
8 |
Correct |
12 ms |
18352 KB |
Output is correct |
9 |
Correct |
20 ms |
21260 KB |
Output is correct |
10 |
Correct |
24 ms |
21300 KB |
Output is correct |
11 |
Correct |
20 ms |
21404 KB |
Output is correct |
12 |
Correct |
8 ms |
17932 KB |
Output is correct |
13 |
Correct |
12 ms |
17864 KB |
Output is correct |
14 |
Correct |
9 ms |
17936 KB |
Output is correct |
15 |
Correct |
11 ms |
17936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
19908 KB |
Output is correct |
2 |
Partially correct |
163 ms |
19752 KB |
Partially correct |
3 |
Correct |
151 ms |
19892 KB |
Output is correct |
4 |
Correct |
26 ms |
19300 KB |
Output is correct |
5 |
Correct |
26 ms |
20808 KB |
Output is correct |
6 |
Correct |
24 ms |
20168 KB |
Output is correct |
7 |
Correct |
27 ms |
20144 KB |
Output is correct |
8 |
Correct |
22 ms |
19776 KB |
Output is correct |
9 |
Correct |
24 ms |
19860 KB |
Output is correct |
10 |
Correct |
280 ms |
19448 KB |
Output is correct |
11 |
Correct |
260 ms |
19428 KB |
Output is correct |
12 |
Correct |
22 ms |
19268 KB |
Output is correct |
13 |
Correct |
30 ms |
19392 KB |
Output is correct |
14 |
Correct |
24 ms |
19180 KB |
Output is correct |
15 |
Partially correct |
37 ms |
19332 KB |
Partially correct |
16 |
Correct |
31 ms |
19352 KB |
Output is correct |
17 |
Partially correct |
26 ms |
19380 KB |
Partially correct |
18 |
Partially correct |
25 ms |
19388 KB |
Partially correct |
19 |
Correct |
24 ms |
19416 KB |
Output is correct |
20 |
Correct |
19 ms |
20280 KB |
Output is correct |
21 |
Correct |
19 ms |
20316 KB |
Output is correct |
22 |
Correct |
23 ms |
20148 KB |
Output is correct |
23 |
Correct |
23 ms |
19904 KB |
Output is correct |
24 |
Correct |
23 ms |
20000 KB |
Output is correct |
25 |
Correct |
23 ms |
20228 KB |
Output is correct |
26 |
Correct |
22 ms |
20036 KB |
Output is correct |
27 |
Correct |
23 ms |
20228 KB |
Output is correct |
28 |
Correct |
24 ms |
19928 KB |
Output is correct |
29 |
Correct |
27 ms |
19908 KB |
Output is correct |
30 |
Correct |
30 ms |
20040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
19944 KB |
Output is correct |
2 |
Correct |
149 ms |
19840 KB |
Output is correct |
3 |
Correct |
161 ms |
19904 KB |
Output is correct |
4 |
Incorrect |
26 ms |
19424 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |