#include "bits/stdc++.h"
using namespace std;
#define ar array
//~ #define int long long
int a[20005];
void MessageBoard(int x, int v) { a[x] = v; }
int Move(int x) { return a[x]; }
namespace JOI{
const int N = 1e4 + 5;
vector<int> G[N], tt;
int used[N], d[N];
void dfs(int u){
used[u] = 1;
tt.push_back(u);
for(auto x : G[u]){
if(used[x]) continue;
d[x] = d[u] + 1;
dfs(x);
}
}
void Joi(int n, int m, int a[], int b[], long long x, int t) {
for(int i=0;i<m;i++){
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
} for(int i=0;i<n;i++){
sort(G[i].begin(), G[i].end());
}
d[0] = 1;
dfs(0);
bool ok = 0;
for(int i=0;i<n;i++){
if(d[i] >= 60){
ok = 1;
} d[i] = (d[i] - 1) % 60;
}
if(ok){
for(int i=0;i<n;i++){;
MessageBoard(i, x >> d[i] & 1);
}
} else {
for(int i=0;i<min(n, 60);i++){
MessageBoard(tt[i], x >> i & 1);
} for(int i=60;i<n;i++){
MessageBoard(tt[i], 0);
}
}
}
}
namespace IOI{
const int N = 1e4 + 5;
int used[N], par[N], d[N];
vector<int> G[N], tt;
void dfs(int u){
used[u] = 1;
tt.push_back(u);
for(auto x : G[u]){
if(used[x]) continue;
d[x] = d[u] + 1,
par[x] = u, dfs(x);
tt.push_back(u);
}
}
long long Ioi(int n, int m, int a[], int b[], int p, int v, int t){
for(int i=0;i<m;i++){
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
} for(int i=0;i<n;i++){
sort(G[i].begin(), G[i].end());
}
d[0] = 1; dfs(0);
int r = -1;
for(int i=0;i<n;i++){
if(d[i] >= 60) r = i;
}
long long x = 0;
if(~r){
if(d[p] >= 60){
for(int j=0;j<60;j++){ d[p] = (d[p] - 1) % 60;
if(v) x |= (1ll << d[p]);
if(p) v = Move(par[p]), p = par[p];
} return x;
} else { tt.clear();
while(p) v = Move(par[p]), p = par[p];
while(r) tt.push_back(r), r = par[r];
for(int i=0;i<60;i++){ d[p] = (d[p] - 1) % 60;
if(v) x |= (1ll << d[p]);
if(tt.empty()){
v = Move(tt.back()), p = tt.back();
tt.pop_back();
}
} return x;
}
}
while(p) v = Move(par[p]), p = par[p];
memset(used, 0, sizeof used);
int cnt = 1; used[0] = 1;
assert(!tt[0]);
x |= v;
tt.erase(tt.begin(), tt.begin() + 1);
for(auto u : tt){
p = u, v = Move(u);
if(used[u]) continue;
if(v) x |= (1ll << cnt);
used[u] = 1; cnt++;
if(cnt == 60) break;
}
return x;
}
}
/*
5 4 23 4 1
1 2
1 3
1 4
0 1
*/
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
long long x;
int n, m, p, t; cin>>n>>m>>x>>p>>t;
int u[20005], v[20005];
for(int i=0;i<m;i++){
cin>>u[i]>>v[i];
} JOI::Joi(n, m, u, v, x, t);
//~ cout<<"here"<<endl;
int res = IOI::Ioi(n, m, u, v, p, a[p], t);
cout<<x<<" "<<res<<"\n";
}
Compilation message
/usr/bin/ld: /tmp/ccYNZEbA.o: in function `MessageBoard(int, int)':
grader_joi.cpp:(.text+0x4e0): multiple definition of `MessageBoard(int, int)'; /tmp/ccVavUuE.o:Joi.cpp:(.text+0x4b0): first defined here
/usr/bin/ld: /tmp/ccYNZEbA.o: in function `main':
grader_joi.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccVavUuE.o:Joi.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccYNZEbA.o: in function `main':
grader_joi.cpp:(.text.startup+0x1ae): undefined reference to `Joi(int, int, int*, int*, long long, int)'
collect2: error: ld returned 1 exit status
/usr/bin/ld: /tmp/ccwepoon.o: in function `main':
grader_ioi.cpp:(.text.startup+0x3f2): undefined reference to `Ioi(int, int, int*, int*, int, int, int)'
collect2: error: ld returned 1 exit status