답안 #486275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486275 2021-11-11T05:12:41 Z kiomi Unique Cities (JOI19_ho_t5) C++17
4 / 100
2000 ms 33624 KB
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")

//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)
//logb(n)=loga(n)/loga(b)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

//(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n
//(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

const int ary=1e6+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
int n,m,c[ary],e[ary],d[ary],ans;
vector<int> g[ary];
set<int> s;
void dfs(int v,int pr=0){
	e[d[v]]++;
	for(int i=0;i<len(g[v]);i++){
		int to=g[v][i];
		if(to==pr){
			continue;
		}
		d[to]=d[v]+1;
		dfs(to,v);
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=1;i<=n;i++){
		s.clear();
		for(int j=0;j<n;j++){
			e[j]=0;
		}
		d[i]=0;
		dfs(i);
		for(int j=1;j<=n;j++){
			if(d[j]&&e[d[j]]==1){
				s.insert(c[j]);
			}
		}
		cout<<len(s)<<"\n";
	}
}

Compilation message

joi2019_ho_t5.cpp:15: warning: "full" redefined
   15 | #define full(x) x.begin(),x.end()
      | 
joi2019_ho_t5.cpp:14: note: this is the location of the previous definition
   14 | #define full(x,n) x,x+n+1
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 77 ms 23916 KB Output is correct
3 Correct 69 ms 23952 KB Output is correct
4 Correct 103 ms 23944 KB Output is correct
5 Correct 89 ms 23916 KB Output is correct
6 Correct 140 ms 24068 KB Output is correct
7 Correct 100 ms 23988 KB Output is correct
8 Correct 86 ms 23888 KB Output is correct
9 Correct 94 ms 23836 KB Output is correct
10 Correct 94 ms 23944 KB Output is correct
11 Correct 89 ms 23884 KB Output is correct
12 Correct 72 ms 23884 KB Output is correct
13 Correct 141 ms 24012 KB Output is correct
14 Correct 93 ms 23884 KB Output is correct
15 Correct 93 ms 23964 KB Output is correct
16 Correct 71 ms 23932 KB Output is correct
17 Correct 105 ms 23936 KB Output is correct
18 Correct 94 ms 23884 KB Output is correct
19 Correct 88 ms 23884 KB Output is correct
20 Correct 274 ms 24132 KB Output is correct
21 Correct 132 ms 24092 KB Output is correct
22 Correct 87 ms 23956 KB Output is correct
23 Correct 91 ms 23940 KB Output is correct
24 Correct 91 ms 23868 KB Output is correct
25 Correct 89 ms 23884 KB Output is correct
26 Correct 76 ms 23928 KB Output is correct
27 Correct 200 ms 24080 KB Output is correct
28 Correct 153 ms 24004 KB Output is correct
29 Correct 100 ms 24012 KB Output is correct
30 Correct 71 ms 23884 KB Output is correct
31 Correct 141 ms 24132 KB Output is correct
32 Correct 108 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2045 ms 30432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2056 ms 33624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 77 ms 23916 KB Output is correct
3 Correct 69 ms 23952 KB Output is correct
4 Correct 103 ms 23944 KB Output is correct
5 Correct 89 ms 23916 KB Output is correct
6 Correct 140 ms 24068 KB Output is correct
7 Correct 100 ms 23988 KB Output is correct
8 Correct 86 ms 23888 KB Output is correct
9 Correct 94 ms 23836 KB Output is correct
10 Correct 94 ms 23944 KB Output is correct
11 Correct 89 ms 23884 KB Output is correct
12 Correct 72 ms 23884 KB Output is correct
13 Correct 141 ms 24012 KB Output is correct
14 Correct 93 ms 23884 KB Output is correct
15 Correct 93 ms 23964 KB Output is correct
16 Correct 71 ms 23932 KB Output is correct
17 Correct 105 ms 23936 KB Output is correct
18 Correct 94 ms 23884 KB Output is correct
19 Correct 88 ms 23884 KB Output is correct
20 Correct 274 ms 24132 KB Output is correct
21 Correct 132 ms 24092 KB Output is correct
22 Correct 87 ms 23956 KB Output is correct
23 Correct 91 ms 23940 KB Output is correct
24 Correct 91 ms 23868 KB Output is correct
25 Correct 89 ms 23884 KB Output is correct
26 Correct 76 ms 23928 KB Output is correct
27 Correct 200 ms 24080 KB Output is correct
28 Correct 153 ms 24004 KB Output is correct
29 Correct 100 ms 24012 KB Output is correct
30 Correct 71 ms 23884 KB Output is correct
31 Correct 141 ms 24132 KB Output is correct
32 Correct 108 ms 23916 KB Output is correct
33 Execution timed out 2045 ms 30432 KB Time limit exceeded
34 Halted 0 ms 0 KB -