#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(100500)
#define sz(x) x.size()
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;
int mrk[N];
int q, n, x, y, i;
vector <int> g[N];
void dfs(int v, int pr)
{
if (mrk[v]) return;
if (pr != -1) mrk[v] = 1;
for (auto u : g[v])
dfs(u, v);
}
int main()
{
// in("input.txt");
// out("output.txt");
ios_base::sync_with_stdio(false);
iostream::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
while (q--)
{
cin >> x >> y;
g[y].pb(x);
}
dfs(1, -1);
for (i = 1; i <= n; i++) cout << mrk[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
37 ms |
5888 KB |
Output is correct |
4 |
Correct |
38 ms |
5880 KB |
Output is correct |
5 |
Correct |
38 ms |
6012 KB |
Output is correct |
6 |
Correct |
42 ms |
6264 KB |
Output is correct |
7 |
Correct |
37 ms |
5880 KB |
Output is correct |
8 |
Correct |
38 ms |
6016 KB |
Output is correct |
9 |
Incorrect |
40 ms |
5880 KB |
Output isn't correct |
10 |
Correct |
41 ms |
6264 KB |
Output is correct |