답안 #886400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886400 2023-12-12T03:23:20 Z Zero_OP 스파이 (JOI13_spy) C++14
100 / 100
88 ms 21120 KB
#include<bits/stdc++.h>

using namespace std;

const int N=2005;
const int M=5e5+5;

int n, m, root[2], dfs_timer[2], tin[2][N], tout[2][N], diff[N][N];
vector<int> g[2][N]; 

void dfs_euler(int type, int u, int e){
	tin[type][u]=++dfs_timer[type];
	for(int i=0; i<g[type][u].size(); ++i){
		int v=g[type][u][i];
		if(v!=e){
			dfs_euler(type, v, u);
		}
	}
	tout[type][u]=dfs_timer[type];
}

void update_intersection(int x1, int y1, int x2, int y2){
	++diff[x1][x2];
	--diff[x1][y2+1];
	--diff[y1+1][x2];
	++diff[y1+1][y2+1];
}

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

	if(fopen("a.inp", "r")){
		freopen("a.inp", "r", stdin);
		freopen("a.out", "w", stdout);
	}

	cin>>n>>m; 
	for(int i=1; i<=n; ++i){
		int u, v; cin>>u>>v;
		if(!u) root[0]=i; 
		else g[0][u].push_back(i);

		if(!v) root[1]=i;
		else g[1][v].push_back(i);

	}

	dfs_euler(0, root[0], root[0]);
	dfs_euler(1, root[1], root[1]);

	for(int i=1; i<=m; ++i){
		int u, v; cin>>u>>v;
		update_intersection(tin[0][u], tout[0][u], tin[1][v], tout[1][v]);
	}

	for(int i=1; i<=n; ++i){
		for(int j=1; j<=n; ++j){
			diff[i][j]+=diff[i-1][j]+diff[i][j-1]-diff[i-1][j-1];
		}
	}

	for(int i=1; i<=n; ++i){
		cout<<diff[tin[0][i]][tin[1][i]]<<'\n';
	}

	return 0;
}

Compilation message

spy.cpp: In function 'void dfs_euler(int, int, int)':
spy.cpp:13:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i=0; i<g[type][u].size(); ++i){
      |               ~^~~~~~~~~~~~~~~~~~
spy.cpp: In function 'int main()':
spy.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   freopen("a.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
spy.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   freopen("a.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16476 KB Output is correct
2 Correct 14 ms 16476 KB Output is correct
3 Correct 14 ms 16220 KB Output is correct
4 Correct 14 ms 16220 KB Output is correct
5 Correct 14 ms 16220 KB Output is correct
6 Correct 14 ms 16220 KB Output is correct
7 Correct 14 ms 16320 KB Output is correct
8 Correct 14 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 21120 KB Output is correct
2 Correct 65 ms 20884 KB Output is correct
3 Correct 68 ms 20564 KB Output is correct
4 Correct 71 ms 20820 KB Output is correct
5 Correct 86 ms 20556 KB Output is correct
6 Correct 61 ms 20052 KB Output is correct
7 Correct 88 ms 20564 KB Output is correct
8 Correct 86 ms 20740 KB Output is correct