[SWEA] 1219 길찾기

Time Lapse :5min 43sec

1219.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <memory.h>
#define gc() getchar_unlocked()
int fRI() {
int ret = 0, N = gc();
for (; 0x30>N || N>0x3A; N = gc());
for (; 0x30 <= N && N <= 0x3A; N = gc()) ret = (ret << 3) + (ret << 1) + (N & 0b1111);
return ret;
}
int m[100][2];
int v[100];
int ans;
void DFS(int cur) {
if (cur == 99) { ans = 1; return; }
if (v[cur]||ans) return;
v[cur] = 1;
if (m[cur][0] != -1) DFS(m[cur][0]);
if (m[cur][1] != -1) DFS(m[cur][1]);
}
int main(int argc, char** argv){
register int T = 11, tc, N, f, e, i;
while (--T) {
tc = fRI(); N = fRI();
memset(m, -1, sizeof(m));
memset(v, 0, sizeof(v));
ans = 0;
for (i = 0; i < N; ++i) {
f = fRI(); e = fRI();
m[f][0] == -1 ? m[f][0] = e : m[f][1] = e;
}
DFS(0);
printf("#%d %d\n",tc, ans);
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/1219/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.