답안 #313918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313918 2020-10-17T09:58:29 Z phathnv Wand (COCI19_wand) C++11
70 / 70
128 ms 4856 KB
#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

wand.cpp: In function 'int main()':
wand.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
wand.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 117 ms 4600 KB Output is correct
4 Correct 114 ms 4600 KB Output is correct
5 Correct 116 ms 4600 KB Output is correct
6 Correct 128 ms 4856 KB Output is correct
7 Correct 116 ms 4600 KB Output is correct
8 Correct 121 ms 4600 KB Output is correct
9 Correct 126 ms 4600 KB Output is correct
10 Correct 128 ms 4856 KB Output is correct