#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,gub1,c=0;
int rj[100007];
map<string, vector<string>> v;
map<string, bool> bio2,bio;
void dfs(string x){
int ivs= stoi(x);
if (bio[x]==1 && (rj[ivs-1]==1 || x=="1")){ rj[c]=1;}
if (bio[x]==1) return;
bio[x]=1;
for (int i=0;i<v[x].size();i++){
dfs(v[x][i]);
}
}
int main(){
cin >> n >> m;
string a,b;
for (int i=0;i<m;i++){
cin >> a >> b;
v[a].pb(b);
if (b=="1") gub1=1;
}
if (gub1==0){
rj[0]=1;
}
for (int i=1;i<=n;i++){
string str=to_string(i);
bio=bio2;
if (i!=1) bio["1"]=1;
dfs(str);
c++;
}
for (int i=0;i<n;i++){
cout << rj[i];
}
return 0;
}
Compilation message
wand.cpp: In function 'void dfs(std::__cxx11::string)':
wand.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[x].size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
12664 KB |
Time limit exceeded |
4 |
Execution timed out |
1089 ms |
12792 KB |
Time limit exceeded |
5 |
Execution timed out |
1093 ms |
13304 KB |
Time limit exceeded |
6 |
Execution timed out |
1049 ms |
12408 KB |
Time limit exceeded |
7 |
Execution timed out |
1053 ms |
12704 KB |
Time limit exceeded |
8 |
Execution timed out |
1049 ms |
13264 KB |
Time limit exceeded |
9 |
Execution timed out |
1090 ms |
13680 KB |
Time limit exceeded |
10 |
Execution timed out |
1088 ms |
13948 KB |
Time limit exceeded |