#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
using namespace std;
const int N = 100005;
int n, m;
bool used[N];
bool ok[N];
vector <int> adj[N];
void dfs(int u, int cnt) {
if (cnt > 0) ok[u] = 1;
used[u] = 1;
for (int v : adj[u]) {
if (!used[v] || v == 1) {
dfs(v, min(2, cnt + 1));
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
adj[y].push_back(x);
}
dfs(1, 0);
if (adj[1].empty()) ok[1] = 1;
for (int i = 1; i <= n; i++) {
cout << ok[i];
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
112 ms |
4728 KB |
Output is correct |
4 |
Correct |
111 ms |
4728 KB |
Output is correct |
5 |
Correct |
113 ms |
4700 KB |
Output is correct |
6 |
Correct |
121 ms |
4716 KB |
Output is correct |
7 |
Correct |
114 ms |
4680 KB |
Output is correct |
8 |
Correct |
115 ms |
4852 KB |
Output is correct |
9 |
Correct |
121 ms |
4728 KB |
Output is correct |
10 |
Correct |
124 ms |
4820 KB |
Output is correct |