Submission #227242

#TimeUsernameProblemLanguageResultExecution timeMemory
227242DavidDamianWand (COCI19_wand)C++11
70 / 70
44 ms5112 KiB
#include <bits/stdc++.h>
using namespace std;
///BFS
///Determine whether the wand can end up in hands of the wizard i
int n,m;
vector<int> adjList[100005];
int color[100005];
queue<int> Q;
void bfs(int s)
{
    Q.push(s);
    while(Q.size()){
        int u=Q.front();
        Q.pop();
        for(int v: adjList[u]){
            if(color[v]==0){
                color[v]=1;
                Q.push(v);
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        adjList[b].push_back(a);
    }
    bfs(1);
    if(adjList[1].size()==0) color[1]=1;
    for(int i=1;i<=n;i++){
        cout<<color[i];
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...