#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
const int maxn = 10005;
static vector<int> g[maxn];
static vector<int> path;
static bool viz[maxn];
// void MessageBoard(int attr, int msg) {
// }
static void dfs(int at) {
path.push_back(at);
viz[at]=true;
for (int to: g[at]) {
if (viz[to]) continue;
dfs(to);
path.push_back(at);
}
}
void Joi(int n, int m, int a[], int b[], long long x, int t) {
for (int i=0; i<=n; i++) {
g[i].clear();
}
path.clear();
memset(viz,false,sizeof(viz));
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());
}
dfs(0);
memset(viz,false,sizeof(viz));
ll j=0;
for (int at: path) {
if (viz[at]) continue;
viz[at]=true;
MessageBoard(at, x>>j&1);
j++;
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 10005;
const int inf = 1e9;
static set<int> g[maxn];
static vector<int> path;
static bool viz[maxn];
int nodes;
// int Move(int dest) {
// cout<<"Move: "<<dest<<endl;
// return 1;
// }
static void dfs(int at) {
path.push_back(at);
viz[at]=true;
for (int to: g[at]) {
if (viz[to]) continue;
dfs(to);
path.push_back(at);
}
}
vector<int> dij(int src) {
int n = nodes;
vector<int> dist(n, inf);
vector<int> par(n, -1);
dist[src] = 0;
queue<int> qq;
qq.push(src);
while (qq.size()) {
int at = qq.front();
qq.pop();
for (int to: g[at]) {
if (dist[to]>1+dist[at]) {
dist[to]=1+dist[at];
par[to]=at;
qq.push(to);
}
}
}
vector<int> res;
int at = 0;
while (at != src) {
res.push_back(at);
at=par[at];
}
reverse(res.begin(), res.end());
return res;
}
long long Ioi(int n, int m, int a[], int b[], int p, int v, int t) {
nodes = n;
for (int i=0; i<=n; i++) {
g[i].clear();
}
path.clear();
memset(viz,false,sizeof(viz));
for (int i=0; i<m; i++) {
g[a[i]].insert(b[i]);
g[b[i]].insert(a[i]);
}
int cur=p;
vector<int> pathto0 = dij(cur);
for (int x: pathto0) {
assert(g[cur].count(x));
assert(x!=-1);
Move(x);
cur=x;
}
assert(cur==0);
int to=*g[cur].begin();
Move(to);
cur=to;
dfs(0);
memset(viz,false,sizeof(viz));
// for (int x: path) {
// cout<<x<<" ";
// }
// cout<<endl;
ll j=0;
ll ans = 0;
for (int nxt: path) {
assert(g[cur].count(nxt));
ll val = Move(nxt);
cur=nxt;
if (viz[nxt]) {
continue;
}
viz[nxt]=true;
if (j>=60) {
break;
}
ans = ans | (val<<j);
j++;
}
return ans;
}
// int main() {
// //long long Ioi(int n, int m, int a[], int b[], int p, int v, int t) {
// int a[] = {0,1,2,2};
// int b[] = {1,2,0,3};
// ll res = Ioi(4,4,a,b,3,0,0);
// watch(res);
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1800 KB |
Output is correct |
2 |
Correct |
10 ms |
1764 KB |
Output is correct |
3 |
Correct |
10 ms |
1752 KB |
Output is correct |
4 |
Correct |
10 ms |
1548 KB |
Output is correct |
5 |
Correct |
10 ms |
1764 KB |
Output is correct |
6 |
Correct |
10 ms |
1792 KB |
Output is correct |
7 |
Correct |
10 ms |
1768 KB |
Output is correct |
8 |
Correct |
10 ms |
1764 KB |
Output is correct |
9 |
Correct |
10 ms |
1556 KB |
Output is correct |
10 |
Correct |
10 ms |
1784 KB |
Output is correct |
11 |
Correct |
15 ms |
2312 KB |
Output is correct |
12 |
Correct |
10 ms |
1540 KB |
Output is correct |
13 |
Correct |
10 ms |
1776 KB |
Output is correct |
14 |
Correct |
10 ms |
1776 KB |
Output is correct |
15 |
Correct |
10 ms |
1776 KB |
Output is correct |
16 |
Correct |
10 ms |
1772 KB |
Output is correct |
17 |
Correct |
10 ms |
1780 KB |
Output is correct |
18 |
Correct |
10 ms |
1780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
6164 KB |
Output is correct |
2 |
Correct |
41 ms |
6736 KB |
Output is correct |
3 |
Correct |
43 ms |
6672 KB |
Output is correct |
4 |
Correct |
27 ms |
4284 KB |
Output is correct |
5 |
Correct |
28 ms |
4712 KB |
Output is correct |
6 |
Correct |
27 ms |
4640 KB |
Output is correct |
7 |
Correct |
27 ms |
4628 KB |
Output is correct |
8 |
Correct |
26 ms |
4576 KB |
Output is correct |
9 |
Correct |
26 ms |
4536 KB |
Output is correct |
10 |
Correct |
25 ms |
4360 KB |
Output is correct |
11 |
Correct |
27 ms |
4416 KB |
Output is correct |
12 |
Correct |
24 ms |
4076 KB |
Output is correct |
13 |
Correct |
25 ms |
4076 KB |
Output is correct |
14 |
Correct |
25 ms |
4016 KB |
Output is correct |
15 |
Correct |
26 ms |
4408 KB |
Output is correct |
16 |
Correct |
26 ms |
4372 KB |
Output is correct |
17 |
Correct |
27 ms |
4412 KB |
Output is correct |
18 |
Correct |
26 ms |
4156 KB |
Output is correct |
19 |
Correct |
26 ms |
4416 KB |
Output is correct |
20 |
Correct |
23 ms |
4540 KB |
Output is correct |
21 |
Correct |
24 ms |
4580 KB |
Output is correct |
22 |
Correct |
26 ms |
4420 KB |
Output is correct |
23 |
Correct |
27 ms |
4540 KB |
Output is correct |
24 |
Correct |
26 ms |
4672 KB |
Output is correct |
25 |
Correct |
26 ms |
4628 KB |
Output is correct |
26 |
Correct |
26 ms |
4596 KB |
Output is correct |
27 |
Correct |
27 ms |
4600 KB |
Output is correct |
28 |
Correct |
26 ms |
4712 KB |
Output is correct |
29 |
Correct |
25 ms |
4300 KB |
Output is correct |
30 |
Correct |
27 ms |
4508 KB |
Output is correct |
31 |
Correct |
10 ms |
1792 KB |
Output is correct |
32 |
Correct |
10 ms |
1636 KB |
Output is correct |
33 |
Correct |
10 ms |
1736 KB |
Output is correct |
34 |
Correct |
10 ms |
1672 KB |
Output is correct |
35 |
Correct |
10 ms |
1552 KB |
Output is correct |
36 |
Correct |
10 ms |
1792 KB |
Output is correct |
37 |
Correct |
10 ms |
1792 KB |
Output is correct |
38 |
Correct |
10 ms |
1804 KB |
Output is correct |
39 |
Correct |
10 ms |
1776 KB |
Output is correct |
40 |
Correct |
10 ms |
1792 KB |
Output is correct |
41 |
Correct |
10 ms |
1792 KB |
Output is correct |
42 |
Correct |
10 ms |
1544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1540 KB |
Output is correct |
2 |
Correct |
10 ms |
1552 KB |
Output is correct |
3 |
Correct |
10 ms |
1668 KB |
Output is correct |
4 |
Correct |
12 ms |
2360 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2136 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
6172 KB |
Output is correct |
2 |
Correct |
41 ms |
6608 KB |
Output is correct |
3 |
Correct |
42 ms |
6680 KB |
Output is correct |
4 |
Partially correct |
27 ms |
4284 KB |
Partially correct |
5 |
Incorrect |
27 ms |
4844 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
6180 KB |
Output is correct |
2 |
Correct |
41 ms |
6692 KB |
Output is correct |
3 |
Correct |
41 ms |
6680 KB |
Output is correct |
4 |
Incorrect |
26 ms |
4256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |