-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc1260.c
More file actions
34 lines (32 loc) · 699 Bytes
/
icpc1260.c
File metadata and controls
34 lines (32 loc) · 699 Bytes
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>
#define MAX_V 1010
void dfs(int u, int edge[], int graph[][MAX_V], int visited[]) {
printf("%d ", u);
visited[u] = 1;
for(int i = 0; i < edge[u]; i++){
int v = graph[u][i];
if(visited[v] == 0)
dfs(v, edge, graph, visited);
}
}
int main() {
int n, m, s;
int edge[MAX_V] = {
0,
};
int visited[MAX_V] = {
0,
};
int graph[MAX_V][MAX_V] = {
0,
};
scanf("%d %d %d", &n, &m, &s);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d %d", &u, &v);
graph[u][edge[u]++] = v;
graph[v][edge[v]++] = u;
}
dfs(s, edge, graph, visited);
return 0;
}