답안 #259863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259863 2020-08-08T17:46:15 Z itiam Wand (COCI19_wand) C++11
70 / 70
592 ms 22396 KB
#include <bits/stdc++.h>

using namespace std;
#define pb push_back

int n,m,gub1,c=0,id=0;
int rj[100007];
map<string, vector<string>> v;
map<string, bool> bio;

void dfs(string x){
    int ivs= stoi(x);
    if (id==1){  rj[ivs-1]=1;return;}
    if (bio[x]==1 && (rj[ivs-1]==1 || x=="1")){  rj[c]=1; id=1;}
    if (bio[x]==1)  return;
    bio[x]=1;
    for (int i=0;i<v[x].size();i++){
        dfs(v[x][i]);
        if (id==1){  rj[ivs-1]=1;return;}
    }

}

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[str]=0;
        id=0;
        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:17: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 0 ms 256 KB Output is correct
3 Correct 549 ms 22008 KB Output is correct
4 Correct 554 ms 21624 KB Output is correct
5 Correct 547 ms 21112 KB Output is correct
6 Correct 580 ms 20904 KB Output is correct
7 Correct 564 ms 20776 KB Output is correct
8 Correct 583 ms 21656 KB Output is correct
9 Correct 592 ms 22064 KB Output is correct
10 Correct 592 ms 22396 KB Output is correct