#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define pib pair<int, bool>
using namespace std;
void count_routes(int n, int m, int p, int r[][2], int q, int g[]){
vector<vector<pair<int, int>>> gr(n, vector<pair<int, int>>(0));
for(int i = 0; i < m; i++){
gr[r[i][0]].push_back(pair<int, int>(i, r[i][1]));
gr[r[i][1]].push_back(pair<int, int>(i, r[i][0]));
}
vector< vector< vector<pib> > > jmp(n, vector< vector<pib> >(18, vector< pair<int, bool> >(2)));
for(int i = 0; i < n; i++){
if(!gr[i].size()){
jmp[i][0][0] = pib(i, 1);
jmp[i][0][1] = pib(i, 1);
}
jmp[i][0][0] = pib(gr[i][0].second, 0);
if(gr[jmp[i][0][0].first][0].second == i){
jmp[i][0][0].second = 1;
}
if(gr[i].size() == 1) jmp[i][0][1] = jmp[i][0][0];
else{
jmp[i][0][1] = pib(gr[i][1].second, 0);
if(gr[jmp[i][0][1].first][0].second == i) jmp[i][0][1].second = 1;
}
}
for(int j = 1; j < 18; j++){
for(int i = 0; i < n; i++){
jmp[i][j][0] = jmp[jmp[i][j - 1][0].first][j - 1][jmp[i][j - 1][0].second];
jmp[i][j][1] = jmp[jmp[i][j - 1][1].first][j - 1][jmp[i][j - 1][1].second];
}
}
for(int j = 0; j < 3; j++){
for(int i = 0; i < n; i++) cout << i << ' ' << j << ' ' << jmp[i][j][0].first << ' ' << jmp[i][j][0].second << ' ' << jmp[i][j][1].first << ' ' << jmp[i][j][1].second << '\n';
}
cout << '\n';
int cur_n, cur_s, cnt = 0, tmp, tmp2, tmp3, tmp4;
for(int i = 0; i < q; i++){
cnt = 0;
for(int j = 0; j < n; j++){
tmp = g[i];
cur_n = j;
cur_s = 0;
tmp2 = 0;
while(tmp){
if(tmp & tmp2){
tmp3 = cur_n;
tmp4 = cur_s;
cout << cur_n << ' ' << cur_s << ' ';
cur_n = jmp[tmp3][tmp2][tmp4].first;
cur_s = jmp[tmp3][tmp2][tmp4].second;
tmp -= 1 << tmp2;
}
tmp2++;
}
cout << cur_n << ' ' << cur_s << '\n';
if(cur_n == p) cnt++;
}
answer(cnt);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |