답안 #35216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35216 2017-11-19T04:28:49 Z wan2000 스파이 (JOI13_spy) C++14
100 / 100
266 ms 18172 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

int n, m, tin[2][N], tout[2][N], counter, D[N][N];
vector<int> Adj[2][N];

void DFS(int u, int type){
    tin[type][u] = counter++;
    for(int i = 0; i < (int)Adj[type][u].size(); i++){
        int v = Adj[type][u][i];
        DFS(v,type);
    }
    tout[type][u] = counter;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i = 1; i <= n; i++){
        int x, y;
        cin>>x>>y;
        Adj[0][x].push_back(i);
        Adj[1][y].push_back(i);
    }
    counter = 0;
    DFS(0,0);
    counter = 0;
    DFS(0,1);
    for(int i = 1; i <= m; i++){
        int a, b;
        cin>>a>>b;
        int x = tin[0][a];
        int u = tout[0][a];
        int y = tin[1][b];
        int v = tout[1][b];
        D[x][y]++;
        D[x][v]--;
        D[u][y]--;
        D[u][v]++;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            D[i][j] += D[i-1][j]+D[i][j-1]-D[i-1][j-1];
        }
    }
    for(int i = 1; i <= n; i++){
        cout<<D[tin[0][i]][tin[1][i]]<<endl;
        //printf("%d\n", D[tin[0][i]][tin[1][i]]);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18004 KB Output is correct
2 Correct 0 ms 18004 KB Output is correct
3 Correct 0 ms 18004 KB Output is correct
4 Correct 0 ms 18004 KB Output is correct
5 Correct 0 ms 18004 KB Output is correct
6 Correct 0 ms 18004 KB Output is correct
7 Correct 3 ms 18004 KB Output is correct
8 Correct 0 ms 18004 KB Output is correct
9 Correct 0 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 18164 KB Output is correct
2 Correct 19 ms 18168 KB Output is correct
3 Correct 49 ms 18004 KB Output is correct
4 Correct 26 ms 18004 KB Output is correct
5 Correct 16 ms 18004 KB Output is correct
6 Correct 16 ms 18004 KB Output is correct
7 Correct 43 ms 18136 KB Output is correct
8 Correct 16 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 18172 KB Output is correct
2 Correct 153 ms 18168 KB Output is correct
3 Correct 159 ms 18004 KB Output is correct
4 Correct 169 ms 18004 KB Output is correct
5 Correct 173 ms 18004 KB Output is correct
6 Correct 129 ms 18004 KB Output is correct
7 Correct 266 ms 18136 KB Output is correct
8 Correct 223 ms 18136 KB Output is correct