Submission #34968

# Submission time Handle Problem Language Result Execution time Memory
34968 2017-11-17T08:59:53 Z itsjustwinds 스파이 (JOI13_spy) C++11
10 / 100
226 ms 262144 KB
#include<bits/stdc++.h>
#define maxn 2005
using namespace std;
int n,r1,r2;
bitset<500005> a[maxn],b[maxn];
vector<int > e1[maxn],e2[maxn];
                bitset<500005> c;
void dfs1(int u)
{
        for (int i=0;i<e1[u].size();++i)
        {
                int v=e1[u][i];
                a[v]=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[v]|b[u];
                dfs2(v);
        }
}
int main()
{
        //freopen("SPY.inp","r",stdin);
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int test;
        cin>>n>>test;
        for (int i=1;i<=n;++i)
        {
                int p,q;
                cin>>p>>q;
                if (p) e1[p].push_back(i);
                else r1=i;
                if (q) e2[q].push_back(i);
                else r2=i;
        }
        while(test--)
        {
                int u,v;
                cin>>u>>v;
                a[u].set(test+1);
                b[v].set(test+1);
        }
        dfs1(r1);
        dfs2(r2);
        for (int i=1;i<=n;++i)
        {
                c=a[i]&b[i];
                cout<<(int)c.count()<<"\n";
        }
        return 0;
}

Compilation message

spy.cpp: In function 'void dfs1(int)':
spy.cpp:10:23: 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:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<e2[u].size();++i)
                       ^
# Verdict Execution time Memory Grader output
1 Correct 19 ms 259196 KB Output is correct
2 Correct 19 ms 259196 KB Output is correct
3 Correct 26 ms 247096 KB Output is correct
4 Correct 19 ms 247096 KB Output is correct
5 Correct 29 ms 247944 KB Output is correct
6 Correct 19 ms 248072 KB Output is correct
7 Correct 29 ms 252284 KB Output is correct
8 Correct 19 ms 249048 KB Output is correct
9 Correct 0 ms 247096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 3 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 226 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -