Submission #1474171


Source Code Expand

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=10010;
int pre[maxn], nxt[maxn], to[maxn], A[maxn], tot=1;
bool vis[maxn],res[maxn];
vector<int>ans;
bool dfs(int x){
	if(vis[x])return res[x];
	vis[x]=1;
	bool flag=false;
	for(int t=pre[x];t;t=nxt[t])if(A[to[t]]<A[x]){
		if(!dfs(to[t])){
			flag=true;
			break;
		}
	}
	if(flag)ans.push_back(x);
	return res[x]=flag;
}
int main(){
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%d",A+i);
	for(int i=1;i< N;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		to[tot]=v, nxt[tot]=pre[u], pre[u]=tot++;
		to[tot]=u, nxt[tot]=pre[v], pre[v]=tot++;
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=N;i++)dfs(i);
	sort(ans.begin(), ans.end());
	if(ans.empty())puts(""); else{
		for(int i=0; i<ans.size()-1; i++)printf("%d ", ans[i]);
		printf("%d\n", ans[ans.size()-1]);
	}
	return 0;
}

Submission Info

Submission Time
Task F - Tree Game
User vjudge1
Language C++14 (GCC 5.4.1)
Score 0
Code Size 909 Byte
Status CE

Compile Error

./Main.cpp:10:1: error: ‘vector’ does not name a type
 vector<int>ans;
 ^
./Main.cpp: In function ‘bool dfs(int)’:
./Main.cpp:21:10: error: ‘ans’ was not declared in this scope
  if(flag)ans.push_back(x);
          ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:36:7: error: ‘ans’ was not declared in this scope
  sort(ans.begin(), ans.end());
       ^
./Main.cpp:26:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
./Main.cpp:27:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++)scanf("%d",A+i);
                                      ^
./Main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
                      ^