Submission #889620

# Submission time Handle Problem Language Result Execution time Memory
889620 2023-12-20T03:59:06 Z vjudge1 Tourism (JOI23_tourism) C++17
10 / 100
5000 ms 14560 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

bool YES(bool f){ if(f) cout << "Yes\n" ; else cout << "No\n" ; return f ; }
void YES(){cout << "Yes\n" ;}
void NO(){cout << "No\n" ;}
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define ld long double
#define pii pair <int , int>
#define ff first
#define ss second
#define endl '\n'

const int N = 3e5 + 5 ;
const int inf = 1e18 ;
const int mod = 998244353 ;
const double eps = 1e-8 ;

int binpow( int a , int b ){
  if ( b == 0 ) return 1 ;
  int x = binpow ( a , b/2 ) ;
  if ( !(b%2) ) return (x*x) ;
  return (x*x*a) ;
}
template <class T>
bool chmax( T& x , const T& y ){
  bool f = 0 ;
  if ( x < y ) x = y , f = 1 ;
  return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
  bool f = 0 ;
  if ( x > y ) x = y , f = 1 ;
  return f ;
}

//code

int n , m , q ;
int c[N] , p[N] ;
vector <int> g[N] ;
bool vis[N] ;


void dfs ( int v , int par ){
	p[v] = par ;
	for ( auto to : g[v] ) if ( to != par ) dfs(to,v) ;
}

void solve(){
	
	cin >> n >> m >> q ;
	for ( int i = 1 ; i < n ; i ++ ){
		int x , y ; cin >> x >> y ;
		g[x].push_back(y) ;
		g[y].push_back(x) ;
	}
	for ( int i = 1 ; i <= m ; i ++ ) cin >> c[i] ;
	if ( max({n,m,q}) <= 2000 ){
		while ( q -- ){
			int l , r ;
			cin >> l >> r ;
			for ( int i = 1 ; i <= n ; i ++ ) vis[i] = 0 ;
			dfs(c[l],0) ; vis[c[l]] = 1 ;
			int ans = 0 ; 
			for ( int i = l+1 ; i <= r ; i ++ ){
				if(vis[c[i]]) continue ;
				vis[c[i]] = 1 ;
				int cur = p[c[i]] ;
				while ( cur != c[l] && !vis[cur] ){
					vis[cur] = 1 ;
					cur = p[cur] ;
				}
			}
			for ( int i = 1 ; i <= n ; i ++ ) ans += vis[i] ;
			cout<< ans << endl ;
		}
		return ;
	}
	while ( q -- ){
		int x , y ; cin >> x >> y ;
		int mn = c[x] , mx = c[x] ;
		for ( int i = x ; i <= y ; i ++ ){
			chmin ( mn , c[i] ) ;
			chmax ( mx , c[i] ) ;
		}
		cout << mx-mn+1 << endl ;
	}
	
}

signed main(){
    ios ;
	int t = 1 ;
	//cin >> t ;
	while ( t -- ) solve() ;
}

Compilation message

tourism.cpp: In function 'void fopn(std::string)':
tourism.cpp:10:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tourism.cpp:10:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10620 KB Output is correct
9 Correct 3 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 3 ms 10588 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10620 KB Output is correct
9 Correct 3 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 3 ms 10588 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 27 ms 10588 KB Output is correct
31 Correct 34 ms 10756 KB Output is correct
32 Correct 54 ms 10588 KB Output is correct
33 Correct 55 ms 10584 KB Output is correct
34 Correct 54 ms 10588 KB Output is correct
35 Correct 52 ms 10584 KB Output is correct
36 Correct 54 ms 10588 KB Output is correct
37 Correct 56 ms 10800 KB Output is correct
38 Correct 45 ms 10588 KB Output is correct
39 Correct 42 ms 10588 KB Output is correct
40 Correct 43 ms 10584 KB Output is correct
41 Correct 44 ms 10588 KB Output is correct
42 Correct 44 ms 10588 KB Output is correct
43 Correct 47 ms 10832 KB Output is correct
44 Correct 42 ms 10840 KB Output is correct
45 Correct 44 ms 10584 KB Output is correct
46 Correct 42 ms 10588 KB Output is correct
47 Correct 44 ms 10804 KB Output is correct
48 Correct 44 ms 10588 KB Output is correct
49 Correct 45 ms 10588 KB Output is correct
50 Correct 20 ms 10584 KB Output is correct
51 Correct 20 ms 10588 KB Output is correct
52 Correct 21 ms 10808 KB Output is correct
53 Correct 21 ms 10588 KB Output is correct
54 Correct 21 ms 10588 KB Output is correct
55 Correct 20 ms 10584 KB Output is correct
56 Correct 2 ms 10584 KB Output is correct
57 Correct 24 ms 10796 KB Output is correct
58 Correct 40 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 3 ms 10588 KB Output is correct
4 Correct 2231 ms 12956 KB Output is correct
5 Correct 1247 ms 13756 KB Output is correct
6 Correct 1502 ms 14068 KB Output is correct
7 Correct 3323 ms 14560 KB Output is correct
8 Correct 3346 ms 14480 KB Output is correct
9 Correct 3334 ms 14448 KB Output is correct
10 Correct 3333 ms 14292 KB Output is correct
11 Correct 3321 ms 14384 KB Output is correct
12 Execution timed out 5013 ms 14260 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Incorrect 17 ms 12636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10584 KB Output is correct
3 Correct 3 ms 10588 KB Output is correct
4 Incorrect 2854 ms 13408 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10620 KB Output is correct
9 Correct 3 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 3 ms 10588 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 27 ms 10588 KB Output is correct
31 Correct 34 ms 10756 KB Output is correct
32 Correct 54 ms 10588 KB Output is correct
33 Correct 55 ms 10584 KB Output is correct
34 Correct 54 ms 10588 KB Output is correct
35 Correct 52 ms 10584 KB Output is correct
36 Correct 54 ms 10588 KB Output is correct
37 Correct 56 ms 10800 KB Output is correct
38 Correct 45 ms 10588 KB Output is correct
39 Correct 42 ms 10588 KB Output is correct
40 Correct 43 ms 10584 KB Output is correct
41 Correct 44 ms 10588 KB Output is correct
42 Correct 44 ms 10588 KB Output is correct
43 Correct 47 ms 10832 KB Output is correct
44 Correct 42 ms 10840 KB Output is correct
45 Correct 44 ms 10584 KB Output is correct
46 Correct 42 ms 10588 KB Output is correct
47 Correct 44 ms 10804 KB Output is correct
48 Correct 44 ms 10588 KB Output is correct
49 Correct 45 ms 10588 KB Output is correct
50 Correct 20 ms 10584 KB Output is correct
51 Correct 20 ms 10588 KB Output is correct
52 Correct 21 ms 10808 KB Output is correct
53 Correct 21 ms 10588 KB Output is correct
54 Correct 21 ms 10588 KB Output is correct
55 Correct 20 ms 10584 KB Output is correct
56 Correct 2 ms 10584 KB Output is correct
57 Correct 24 ms 10796 KB Output is correct
58 Correct 40 ms 10588 KB Output is correct
59 Correct 2 ms 10588 KB Output is correct
60 Correct 2 ms 10588 KB Output is correct
61 Correct 3 ms 10588 KB Output is correct
62 Correct 2231 ms 12956 KB Output is correct
63 Correct 1247 ms 13756 KB Output is correct
64 Correct 1502 ms 14068 KB Output is correct
65 Correct 3323 ms 14560 KB Output is correct
66 Correct 3346 ms 14480 KB Output is correct
67 Correct 3334 ms 14448 KB Output is correct
68 Correct 3333 ms 14292 KB Output is correct
69 Correct 3321 ms 14384 KB Output is correct
70 Execution timed out 5013 ms 14260 KB Time limit exceeded
71 Halted 0 ms 0 KB -