# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313918 | phathnv | Wand (COCI19_wand) | C++11 | 128 ms | 4856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "WAND"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 100001;
int n, m;
vector <int> adj[N];
bool vst[N];
void readInput(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
adj[v].push_back(u);
}
}
void dfs(int u){
for(int v : adj[u]){
if (vst[v])
continue;
vst[v] = 1;
dfs(v);
}
}
void solve(){
dfs(1);
if (adj[1].empty())
vst[1] = 1;
for(int i = 1; i <= n; i++)
cout << (vst[i]? '1' : '0');
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
readInput();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |