Submission #168329

# Submission time Handle Problem Language Result Execution time Memory
168329 2019-12-12T12:22:07 Z Asamu13 Birokracija (COCI18_birokracija) C++14
100 / 100
136 ms 27320 KB
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;
 
//int visit[200013];
long long bas[200013];
long long is[200013];
long long par[200013];
vector< int > tut;
vector< vector<long long> > grp;

void dfs(int x){
	tut.pb(x);
	for(int i=0;i<grp[x].size();i++){
		par[grp[x][i]]=x;
		dfs(grp[x][i]);
	}

	return;
}

 
int main(){
	long long n;
	cin>>n;
	for(int i=0;i<=n;i++){
		vector<long long> aaa;
		grp.pb(aaa);
	}
	for(long long i=2;i<=n;i++){
		int k;
		sc(k);
		grp[k].pb(i);
	}
	dfs(1);
	for(int i=tut.size()-1;i>0;i--){
		int k=tut[i];
		bas[k]++;
		is[k]++;
		is[par[k]]+=is[k];
		bas[par[k]]+=bas[k]+is[k];
	}
	bas[1]++;
	for(int i=1;i<=n;i++){
		cout<<bas[i]<<" ";
	}

	


	
	return 0;
}

Compilation message

birokracija.cpp: In function 'void dfs(int)':
birokracija.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<grp[x].size();i++){
              ~^~~~~~~~~~~~~~
birokracija.cpp: In function 'int main()':
birokracija.cpp:3:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sc(a) scanf("%d",&a)
               ~~~~~^~~~~~~~~
birokracija.cpp:51:3: note: in expansion of macro 'sc'
   sc(k);
   ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2032 KB Output is correct
2 Correct 13 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 6372 KB Output is correct
2 Correct 36 ms 6496 KB Output is correct
3 Correct 36 ms 7392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 16600 KB Output is correct
2 Correct 95 ms 18440 KB Output is correct
3 Correct 98 ms 27320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 16856 KB Output is correct
2 Correct 97 ms 17632 KB Output is correct
3 Correct 94 ms 19504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 16568 KB Output is correct
2 Correct 102 ms 17844 KB Output is correct
3 Correct 94 ms 20388 KB Output is correct