#include<iostream>
#include<vector>
using namespace std;
vector<vector<int> > g;
vector<bool> v;
void dfs(int s) {
for(int u=0;u<g[s].size();u++) {
if(!v[g[s][u]]) {
v[g[s][u]] = 1;
dfs(g[s][u]);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> vi;
g.insert(g.begin(),n+1,vi);
v.insert(v.begin(),n+1,0);
int a, b;
for(int i=0;i<m;i++) {
cin >> b >> a;
a--; b--;
g[a].push_back(b);
}
dfs(0);
bool ok = 0;
for(int i=1;i<n;i++) {
if(v[i]==1) ok = 1;
}
if(ok) {
for(int i=0;i<n;i++) {
cout << v[i];
}
}
else {
cout << 1;
for(int i=1;i<n;i++) {
cout << 0;
}
}
return 0;
}
Compilation message
wand.cpp: In function 'void dfs(int)':
wand.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int u=0;u<g[s].size();u++) {
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
37 ms |
5496 KB |
Output is correct |
4 |
Correct |
35 ms |
5496 KB |
Output is correct |
5 |
Correct |
39 ms |
5368 KB |
Output is correct |
6 |
Correct |
66 ms |
5496 KB |
Output is correct |
7 |
Correct |
59 ms |
5368 KB |
Output is correct |
8 |
Correct |
44 ms |
5624 KB |
Output is correct |
9 |
Correct |
41 ms |
5880 KB |
Output is correct |
10 |
Correct |
70 ms |
5852 KB |
Output is correct |