Submission #836112

# Submission time Handle Problem Language Result Execution time Memory
836112 2023-08-24T07:29:51 Z josanneo22 Tourism (JOI23_tourism) C++17
10 / 100
5000 ms 10552 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;
	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:55:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |      freopen("input.txt","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
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("output.txt","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 316 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 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 316 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 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 21 ms 464 KB Output is correct
31 Correct 27 ms 424 KB Output is correct
32 Correct 45 ms 468 KB Output is correct
33 Correct 43 ms 512 KB Output is correct
34 Correct 42 ms 464 KB Output is correct
35 Correct 43 ms 496 KB Output is correct
36 Correct 43 ms 500 KB Output is correct
37 Correct 45 ms 512 KB Output is correct
38 Correct 57 ms 704 KB Output is correct
39 Correct 54 ms 720 KB Output is correct
40 Correct 57 ms 724 KB Output is correct
41 Correct 54 ms 700 KB Output is correct
42 Correct 54 ms 692 KB Output is correct
43 Correct 57 ms 704 KB Output is correct
44 Correct 61 ms 596 KB Output is correct
45 Correct 55 ms 468 KB Output is correct
46 Correct 54 ms 588 KB Output is correct
47 Correct 55 ms 468 KB Output is correct
48 Correct 57 ms 560 KB Output is correct
49 Correct 55 ms 596 KB Output is correct
50 Correct 37 ms 524 KB Output is correct
51 Correct 39 ms 520 KB Output is correct
52 Correct 32 ms 516 KB Output is correct
53 Correct 38 ms 512 KB Output is correct
54 Correct 35 ms 468 KB Output is correct
55 Correct 33 ms 504 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 43 ms 484 KB Output is correct
58 Correct 47 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 5050 ms 10552 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2761 ms 5460 KB Output is correct
3 Correct 3153 ms 6304 KB Output is correct
4 Correct 3401 ms 6692 KB Output is correct
5 Correct 34 ms 9700 KB Output is correct
6 Correct 49 ms 9876 KB Output is correct
7 Correct 59 ms 9712 KB Output is correct
8 Correct 116 ms 9704 KB Output is correct
9 Correct 326 ms 9680 KB Output is correct
10 Correct 903 ms 9708 KB Output is correct
11 Correct 2870 ms 9716 KB Output is correct
12 Execution timed out 5013 ms 9732 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Execution timed out 5040 ms 6508 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 316 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 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 21 ms 464 KB Output is correct
31 Correct 27 ms 424 KB Output is correct
32 Correct 45 ms 468 KB Output is correct
33 Correct 43 ms 512 KB Output is correct
34 Correct 42 ms 464 KB Output is correct
35 Correct 43 ms 496 KB Output is correct
36 Correct 43 ms 500 KB Output is correct
37 Correct 45 ms 512 KB Output is correct
38 Correct 57 ms 704 KB Output is correct
39 Correct 54 ms 720 KB Output is correct
40 Correct 57 ms 724 KB Output is correct
41 Correct 54 ms 700 KB Output is correct
42 Correct 54 ms 692 KB Output is correct
43 Correct 57 ms 704 KB Output is correct
44 Correct 61 ms 596 KB Output is correct
45 Correct 55 ms 468 KB Output is correct
46 Correct 54 ms 588 KB Output is correct
47 Correct 55 ms 468 KB Output is correct
48 Correct 57 ms 560 KB Output is correct
49 Correct 55 ms 596 KB Output is correct
50 Correct 37 ms 524 KB Output is correct
51 Correct 39 ms 520 KB Output is correct
52 Correct 32 ms 516 KB Output is correct
53 Correct 38 ms 512 KB Output is correct
54 Correct 35 ms 468 KB Output is correct
55 Correct 33 ms 504 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 43 ms 484 KB Output is correct
58 Correct 47 ms 504 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Execution timed out 5050 ms 10552 KB Time limit exceeded
63 Halted 0 ms 0 KB -