답안 #35008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35008 2017-11-17T09:21:35 Z itsjustwinds 스파이 (JOI13_spy) C++14
100 / 100
363 ms 247104 KB
#include<bits/stdc++.h>
#define maxn 2005
#define FOR(i, a, b) for (int i = a; i<=b ; i++)
#define FORD(i, a, b) for (int i = a; i>=b; i--)
#define REP(i, a) for (int i = 0; i<a; i++)
#define M 501000
#define N 2020
#define pp pair<int, int>
#define IO cin.tie(NULL);cout.tie(NULL);
#define bit(S, i) ((S >> i) & 1)
using namespace std;
int n,r1,r2;
bitset<500005> a[maxn],b[maxn];
vector<int > e1[maxn],e2[maxn];
bitset<500005> c;
template<typename T> inline void read(T &x)
{
        char c;
        bool neg = false;
        while (!isdigit(c = getchar()) && c != '-');
        x = 0;
        if (c == '-')
        {
                neg = true;
                c = getchar();
        }
        do
        {
                x = x * 10 + c - '0';
        }
        while (isdigit(c = getchar()));
        if (neg) x = -x;
}
template<typename T> inline void write(T x)
{
        if (x < 0)
        {
                putchar('-');
                write(-x);
                return;
        }
        if (x < 10)
        {
                putchar(char(x + 48));
        }
        else
        {
                write(x/10);
                putchar(char(48 + x%10));
        }
}
template<typename T> inline void writeln(T x)
{
        write(x);
        putchar('\n');
}
void dfs1(int u)
{
        for (int i=0; i<e1[u].size(); ++i)
        {
                int v=e1[u][i];
                a[v]|=a[u];
                dfs1(v);
        }
}
void dfs2(int u)
{
        for (int i=0; i<e2[u].size(); ++i)
        {
                int v=e2[u][i];
                b[v]|=b[u];
                dfs2(v);
        }
}
int p,q,u,v;
int main()
{
        //freopen("SPY.inp","r",stdin);
        IO;
        int test;
        read(n);
        read(test);
        //cin>>n>>test;
        FOR(i, 1, n)
        {
                read(p);
                read(q);
                if (p) e1[p].push_back(i);
                else r1=i;
                if (q) e2[q].push_back(i);
                else r2=i;
        }
        REP(i, test)
        {
                read(u);
                read(v);
                a[u].set(i);
                b[v].set(i);
        }
        dfs1(r1);
        dfs2(r2);
        for (int i=1; i<=n; ++i)
        {
                c=a[i]&b[i];
                writeln(c.count());
        }
        return 0;
}

Compilation message

spy.cpp: In function 'void dfs1(int)':
spy.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0; i<e1[u].size(); ++i)
                        ^
spy.cpp: In function 'void dfs2(int)':
spy.cpp:68:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0; i<e2[u].size(); ++i)
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 246940 KB Output is correct
2 Correct 16 ms 246940 KB Output is correct
3 Correct 16 ms 246940 KB Output is correct
4 Correct 19 ms 246940 KB Output is correct
5 Correct 19 ms 246940 KB Output is correct
6 Correct 16 ms 246940 KB Output is correct
7 Correct 23 ms 246940 KB Output is correct
8 Correct 16 ms 246940 KB Output is correct
9 Correct 0 ms 246940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 247104 KB Output is correct
2 Correct 189 ms 247104 KB Output is correct
3 Correct 183 ms 246940 KB Output is correct
4 Correct 149 ms 246940 KB Output is correct
5 Correct 186 ms 247072 KB Output is correct
6 Correct 186 ms 247072 KB Output is correct
7 Correct 183 ms 247072 KB Output is correct
8 Correct 153 ms 247072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 353 ms 247100 KB Output is correct
2 Correct 233 ms 247100 KB Output is correct
3 Correct 286 ms 246940 KB Output is correct
4 Correct 303 ms 246940 KB Output is correct
5 Correct 349 ms 247072 KB Output is correct
6 Correct 229 ms 247072 KB Output is correct
7 Correct 356 ms 247072 KB Output is correct
8 Correct 363 ms 247072 KB Output is correct