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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int d[1005][1005];
void warshall_floyd(int n, int m) {
rep(i,n) rep(j,n) d[i][j] = INF;
rep(i,n) d[i][i] = 0;
rep(i, m) {
int s, t;
cin >> s >> t;
s--;
t--;
d[s][t] = 1;
d[t][s] = 1;
}
rep(k, n) {
rep(i, n) {
rep(j, n) {
if(d[i][k] == INF || d[k][j] == INF) continue;
d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
}
}
}
}
int main() {
int n, m;
while(cin >> n >> m) {
if(n == 0 && m == 0) break;
warshall_floyd(n, m);
int ans = 0;
rep(i, n) {
if(i == 0) continue;
if(d[0][i] <= 2) {
ans++;
}
}
cout << ans << endl;
}
return 0;
}
|