답안 #34951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34951 2017-11-17T08:48:43 Z long10024070 스파이 (JOI13_spy) C++11
10 / 100
2000 ms 3400 KB
#define Link ""

#include <iostream>
#include <cstdio>
#include <vector>

#define TASK "SPY"

using namespace std;

void OpenFile()
{
    freopen(".INP","r",stdin);
    freopen(".OUT","w",stdout);
}

const int maxn = 2e4 + 1;
int n,m,lab[maxn],res[maxn];
vector <int> e[2][maxn];

int FastIn()
{
    int res = 0;
    register char c = getchar();
    while (c < '0' || '9' < c) c = getchar();
    while ('0' <= c && c <= '9') res = res * 10 + c - '0', c = getchar();
    return res;
}

void Enter()
{
    n = FastIn();
    m = FastIn();
    for (int i=1;i<=n;++i) {
        e[0][FastIn()].push_back(i);
        e[1][FastIn()].push_back(i);
    }
}

void Init()
{

}

void DFS(int t, int u)
{
    if (t == 0)
        lab[u] = m;
    else
        if (lab[u] == m)
            ++res[u];
    for (int v : e[t][u])
        DFS(t,v);
}

void Solve()
{
    for (;m>0;--m) {
        int R,S;
        R = FastIn();
        S = FastIn();
        DFS(0,R);
        DFS(1,S);
    }
    for (int i=1;i<=n;++i)
        cout << res[i] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //OpenFile();

    Enter();
    Init();
    Solve();
}

Compilation message

spy.cpp: In function 'void OpenFile()':
spy.cpp:13:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(".INP","r",stdin);
                              ^
spy.cpp:14:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(".OUT","w",stdout);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3268 KB Output is correct
2 Correct 0 ms 3268 KB Output is correct
3 Correct 0 ms 3268 KB Output is correct
4 Correct 0 ms 3268 KB Output is correct
5 Correct 0 ms 3268 KB Output is correct
6 Correct 0 ms 3268 KB Output is correct
7 Correct 0 ms 3268 KB Output is correct
8 Correct 0 ms 3268 KB Output is correct
9 Correct 0 ms 3268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 3400 KB Output is correct
2 Runtime error 216 ms 3400 KB Execution killed because of forbidden syscall writev (20)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 3400 KB Execution timed out
2 Halted 0 ms 0 KB -