답안 #836113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836113 2023-08-24T07:30:58 Z josanneo22 Tourism (JOI23_tourism) C++17
10 / 100
3384 ms 8036 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ar array

/*tourism
subtask 1&2: make root at l[i] then just find number of nodes passed through

*/
void solve(){
	int n,m,q; cin>>n>>m>>q;
  	if(n*q>=2e8+600){ cout<<0<<'\n'; return; }
	vector<vector<int>> g(n+1);
	for(int i=0;i<n-1;i++){
		int u,v; cin>>u>>v;
		g[u].pb(v); g[v].pb(u);
	}
	vector<int> c(m+1),d(n+1);
	function<void(int,int)> dfs=[&](int u,int f){
		for(auto&v:g[u]){
			if(v==f) continue;
			dfs(v,u);
			d[u]+=d[v];
		}
	};
	for(int i=1;i<=m;i++) cin>>c[i];
	auto reset=[&](int l,int r){
		for(int i=1;i<=n;i++) d[i]=0;
		for(int i=l;i<=r;i++) d[c[i]]=1;
	};
	auto ans=[&](int l,int r){
		reset(l,r);
		dfs(c[l],0);
		int rs=0;
		for(int i=1;i<=n;i++) if(d[i]>=1) rs++;
		cout<<rs<<'\n';
	};
	while(q--){
		int l,r; cin>>l>>r;
		ans(l,r);
	}
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	clock_t tStart = clock();
	int local=0,multi=0,debug=1,tt=1;
	if(local){
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	}	
	if(multi) cin>>tt;
	for(int i=1;i<=tt;i++){
		if(debug && multi && local) cout<<"样例 "<<i<<'\n';
		solve();
 	}
	fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}

Compilation message

tourism.cpp: In function 'int main()':
tourism.cpp:56:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |      freopen("input.txt","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tourism.cpp:57:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |      freopen("output.txt","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 21 ms 340 KB Output is correct
31 Correct 28 ms 340 KB Output is correct
32 Correct 42 ms 468 KB Output is correct
33 Correct 42 ms 468 KB Output is correct
34 Correct 42 ms 468 KB Output is correct
35 Correct 43 ms 468 KB Output is correct
36 Correct 43 ms 468 KB Output is correct
37 Correct 43 ms 516 KB Output is correct
38 Correct 54 ms 596 KB Output is correct
39 Correct 53 ms 672 KB Output is correct
40 Correct 54 ms 596 KB Output is correct
41 Correct 60 ms 672 KB Output is correct
42 Correct 59 ms 652 KB Output is correct
43 Correct 65 ms 652 KB Output is correct
44 Correct 57 ms 588 KB Output is correct
45 Correct 54 ms 524 KB Output is correct
46 Correct 55 ms 468 KB Output is correct
47 Correct 57 ms 468 KB Output is correct
48 Correct 56 ms 500 KB Output is correct
49 Correct 56 ms 540 KB Output is correct
50 Correct 32 ms 468 KB Output is correct
51 Correct 32 ms 468 KB Output is correct
52 Correct 32 ms 468 KB Output is correct
53 Correct 33 ms 596 KB Output is correct
54 Correct 35 ms 468 KB Output is correct
55 Correct 34 ms 488 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 42 ms 340 KB Output is correct
58 Correct 41 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2693 ms 4508 KB Output is correct
3 Correct 3089 ms 5220 KB Output is correct
4 Correct 3384 ms 5488 KB Output is correct
5 Correct 32 ms 7892 KB Output is correct
6 Correct 54 ms 8036 KB Output is correct
7 Correct 56 ms 7892 KB Output is correct
8 Correct 113 ms 7892 KB Output is correct
9 Correct 326 ms 7980 KB Output is correct
10 Correct 880 ms 7892 KB Output is correct
11 Correct 2905 ms 7988 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 21 ms 340 KB Output is correct
31 Correct 28 ms 340 KB Output is correct
32 Correct 42 ms 468 KB Output is correct
33 Correct 42 ms 468 KB Output is correct
34 Correct 42 ms 468 KB Output is correct
35 Correct 43 ms 468 KB Output is correct
36 Correct 43 ms 468 KB Output is correct
37 Correct 43 ms 516 KB Output is correct
38 Correct 54 ms 596 KB Output is correct
39 Correct 53 ms 672 KB Output is correct
40 Correct 54 ms 596 KB Output is correct
41 Correct 60 ms 672 KB Output is correct
42 Correct 59 ms 652 KB Output is correct
43 Correct 65 ms 652 KB Output is correct
44 Correct 57 ms 588 KB Output is correct
45 Correct 54 ms 524 KB Output is correct
46 Correct 55 ms 468 KB Output is correct
47 Correct 57 ms 468 KB Output is correct
48 Correct 56 ms 500 KB Output is correct
49 Correct 56 ms 540 KB Output is correct
50 Correct 32 ms 468 KB Output is correct
51 Correct 32 ms 468 KB Output is correct
52 Correct 32 ms 468 KB Output is correct
53 Correct 33 ms 596 KB Output is correct
54 Correct 35 ms 468 KB Output is correct
55 Correct 34 ms 488 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 42 ms 340 KB Output is correct
58 Correct 41 ms 468 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 2 ms 340 KB Output is correct
62 Incorrect 0 ms 212 KB Output isn't correct
63 Halted 0 ms 0 KB -