#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int i, n, m, s, g, j, kk, ch;
vector<int> C;
vector<int> X;
vector<int> Y;
vector<int> adj[100005];
bool visited[100005];
bool finished[200005];
vector<vector<int> > groups;
vector<int> tmp;
bool vis;
vector<int> sw;
vector<int> st;
vector<pair<int, int> > pos;
void new_switch() {
sw.push_back(--s);
st.push_back(0);
X.push_back(sw.front());
Y.push_back(sw.front());
}
void dfs(int x) {
if (st[-x-1] == 0) {
st[-x-1] ^= 1;
if (X[-x-1] == sw.front()) pos.push_back(make_pair(-x-1, 0));
else dfs(X[-x-1]);
}
else {
st[-x-1] ^= 1;
if (Y[-x-1] == sw.front()) pos.push_back(make_pair(-x-1, 1));
else dfs(Y[-x-1]);
}
}
void create_switch(int i) {
int num = (int)adj[i].size();
if (num == 0) C[i] = i;
else if (num == 1) C[i] = adj[i][0];
else {
sw.clear();
new_switch();
C[i] = s;
ch = 2;
while (ch < num) {
new_switch();
if (j&1) X[-sw[j>>1]-1] = s;
else {
ch += 2;
Y[-sw[(j-1)>>1]-1] = s;
}
}
pos.clear();
for (int j=0; j < ch; ++j) dfs(sw.front());
for (j=num-1; j >= 0; --j) {
if (pos[kk].second == 0) X[pos[kk].first] = adj[i][j];
else Y[pos[kk].first] = adj[i][j];
--kk;
}
}
}
void create_circuit(int M, vector<int> A) {
m = M;
n = (int)A.size();
fill(finished, finished+n+1, false);
C.resize(m+1);
X.clear();
Y.clear();
st.clear();
s = 0;
A.push_back(0);
for (i=0; i < n; ++i) adj[A[i]].push_back(A[i+1]);
C[0] = A[0];
for (i=1; i <= m; ++i) create_switch(i);
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
19 ms |
6352 KB |
Output is correct |
3 |
Correct |
14 ms |
6108 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
23 ms |
8040 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
19 ms |
6352 KB |
Output is correct |
3 |
Correct |
14 ms |
6108 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
23 ms |
8040 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Runtime error |
21 ms |
12264 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
19 ms |
6352 KB |
Output is correct |
3 |
Correct |
14 ms |
6108 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
23 ms |
8040 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Runtime error |
21 ms |
12264 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5196 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5196 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |