답안 #34013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34013 2017-11-06T05:32:08 Z Dat160601 스파이 (JOI13_spy) C++14
10 / 100
579 ms 65160 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,u,v,vis[2007],root1,root2,cnt=0;
int st[2007],fs[2007];
int st2[2007],fs2[2007],dp[4007][4007];
vector < int > edge[2007],ed[2007];
void dfs1(int u){
	cnt++;
	st[u]=cnt;
	for(int i=0;i<(int)edge[u].size();i++){
		int v=edge[u][i];
		dfs1(v);
	}
	cnt++;
	fs[u]=cnt;
}
void dfs2(int u){
	cnt++;
	st2[u]=cnt;
	for(int i=0;i<(int)ed[u].size();i++){
		int v=ed[u][i];
		dfs2(v);
	}
	cnt++;
	fs2[u]=cnt;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>u>>v;
		if(u==0){
			root1=i;
		}
		else edge[u].pb(i);
		if(v==0){
			root2=i;
		}
		else ed[v].pb(i);
	}
	dfs1(root1);
	cnt=0;
	dfs2(root2);
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		dp[st[u]][st2[v]]++;
		dp[st[u]][fs2[v]]--;
		dp[fs[u]][fs2[v]]++;
		dp[fs[u]][st2[v]]--;
	}
	int cur=0;
	for(int i=1;i<=2*n;i++){
		cur=0;
		for(int j=1;j<=2*n;j++){
			cur+=dp[j][i];
			dp[j][i]=cur;
		}
	}
	for(int i=1;i<=2*n;i++){
		cur=0;
		for(int j=1;j<=2*n;j++){
			cur+=dp[i][j];
			dp[i][j]=cur;
		}
	}
	for(int i=1;i<=n;i++){
		cout<<dp[st[i]][st2[i]]<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 65028 KB Output is correct
2 Correct 0 ms 65028 KB Output is correct
3 Correct 3 ms 65028 KB Output is correct
4 Correct 0 ms 65028 KB Output is correct
5 Correct 3 ms 65028 KB Output is correct
6 Correct 0 ms 65028 KB Output is correct
7 Correct 3 ms 65028 KB Output is correct
8 Correct 3 ms 65028 KB Output is correct
9 Correct 0 ms 65028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 473 ms 65160 KB Output is correct
2 Runtime error 439 ms 65160 KB Execution killed because of forbidden syscall writev (20)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 579 ms 65160 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -