답안 #676152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676152 2022-12-29T14:29:48 Z Cookie 스파이 (JOI13_spy) C++14
100 / 100
342 ms 249864 KB
#include<bits/stdc++.h>
 
#include<fstream>
 
using namespace std;

#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 2e3, mxm = 5e5;
bitset<mxm>ioi[mxn + 1], joi[mxn + 1];
int p[mxn + 1], q[mxn + 1];
int n, m, rootj, rooti;
vt<int>adj[mxn + 1], g[mxn + 1]; 
void dfs(int s, int pre){
    for(auto i: adj[s]){
        joi[i] |= joi[s];
        dfs(i, s);
    }
}
void dfs2(int s, int pre){
    for(auto i: g[s]){
        ioi[i] |= ioi[s];
        dfs2(i, s);
    }
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
        if(p[i])adj[p[i]].pb(i);
        else rootj = i;
        cin >> q[i];
        if(q[i])g[q[i]].pb(i);
        else rooti = i;
    }
    for(int i = 0; i < m; i++){
        int r, b; cin >> r >> b;
        joi[r][i] = 1; ioi[b][i] = 1;
    }
    dfs(rootj, -1); dfs2(rooti, -1);
    for(int i = 1; i <= n; i++){
        cout << (joi[i] & ioi[i]).count() << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24864 KB Output is correct
2 Correct 17 ms 24780 KB Output is correct
3 Correct 17 ms 24852 KB Output is correct
4 Correct 18 ms 24788 KB Output is correct
5 Correct 18 ms 24852 KB Output is correct
6 Correct 17 ms 24788 KB Output is correct
7 Correct 17 ms 24788 KB Output is correct
8 Correct 19 ms 24796 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 245192 KB Output is correct
2 Correct 167 ms 245252 KB Output is correct
3 Correct 166 ms 244976 KB Output is correct
4 Correct 194 ms 245052 KB Output is correct
5 Correct 165 ms 245172 KB Output is correct
6 Correct 167 ms 245040 KB Output is correct
7 Correct 172 ms 245184 KB Output is correct
8 Correct 172 ms 245072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 291 ms 249624 KB Output is correct
2 Correct 247 ms 249548 KB Output is correct
3 Correct 293 ms 249604 KB Output is correct
4 Correct 279 ms 249864 KB Output is correct
5 Correct 301 ms 249552 KB Output is correct
6 Correct 223 ms 249080 KB Output is correct
7 Correct 298 ms 249620 KB Output is correct
8 Correct 342 ms 249700 KB Output is correct