# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
889611 | 2023-12-20T03:52:14 Z | vjudge1 | Tourism (JOI23_tourism) | C++17 | 5000 ms | 14680 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] ; 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 ; } } signed main(){ ios ; int t = 1 ; //cin >> t ; while ( t -- ) solve() ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10588 KB | Output is correct |
2 | Correct | 3 ms | 10584 KB | Output is correct |
3 | Correct | 2 ms | 10588 KB | Output is correct |
4 | Correct | 4 ms | 10588 KB | Output is correct |
5 | Correct | 2 ms | 10584 KB | Output is correct |
6 | Correct | 2 ms | 10584 KB | Output is correct |
7 | Correct | 2 ms | 10588 KB | Output is correct |
8 | Correct | 2 ms | 10676 KB | Output is correct |
9 | Correct | 3 ms | 10736 KB | Output is correct |
10 | Correct | 3 ms | 10588 KB | Output is correct |
11 | Correct | 3 ms | 10588 KB | Output is correct |
12 | Correct | 3 ms | 10588 KB | Output is correct |
13 | Correct | 3 ms | 10588 KB | Output is correct |
14 | Correct | 3 ms | 10588 KB | Output is correct |
15 | Correct | 3 ms | 10588 KB | Output is correct |
16 | Correct | 3 ms | 10676 KB | Output is correct |
17 | Correct | 3 ms | 10588 KB | Output is correct |
18 | Correct | 3 ms | 10680 KB | Output is correct |
19 | Correct | 3 ms | 10600 KB | Output is correct |
20 | Correct | 3 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 4 ms | 10588 KB | Output is correct |
23 | Correct | 3 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10588 KB | Output is correct |
25 | Correct | 3 ms | 10588 KB | Output is correct |
26 | Correct | 2 ms | 10588 KB | Output is correct |
27 | Correct | 2 ms | 10588 KB | Output is correct |
28 | Correct | 3 ms | 10588 KB | Output is correct |
29 | Correct | 2 ms | 10588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10588 KB | Output is correct |
2 | Correct | 3 ms | 10584 KB | Output is correct |
3 | Correct | 2 ms | 10588 KB | Output is correct |
4 | Correct | 4 ms | 10588 KB | Output is correct |
5 | Correct | 2 ms | 10584 KB | Output is correct |
6 | Correct | 2 ms | 10584 KB | Output is correct |
7 | Correct | 2 ms | 10588 KB | Output is correct |
8 | Correct | 2 ms | 10676 KB | Output is correct |
9 | Correct | 3 ms | 10736 KB | Output is correct |
10 | Correct | 3 ms | 10588 KB | Output is correct |
11 | Correct | 3 ms | 10588 KB | Output is correct |
12 | Correct | 3 ms | 10588 KB | Output is correct |
13 | Correct | 3 ms | 10588 KB | Output is correct |
14 | Correct | 3 ms | 10588 KB | Output is correct |
15 | Correct | 3 ms | 10588 KB | Output is correct |
16 | Correct | 3 ms | 10676 KB | Output is correct |
17 | Correct | 3 ms | 10588 KB | Output is correct |
18 | Correct | 3 ms | 10680 KB | Output is correct |
19 | Correct | 3 ms | 10600 KB | Output is correct |
20 | Correct | 3 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 4 ms | 10588 KB | Output is correct |
23 | Correct | 3 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10588 KB | Output is correct |
25 | Correct | 3 ms | 10588 KB | Output is correct |
26 | Correct | 2 ms | 10588 KB | Output is correct |
27 | Correct | 2 ms | 10588 KB | Output is correct |
28 | Correct | 3 ms | 10588 KB | Output is correct |
29 | Correct | 2 ms | 10588 KB | Output is correct |
30 | Correct | 29 ms | 10588 KB | Output is correct |
31 | Correct | 34 ms | 10588 KB | Output is correct |
32 | Correct | 66 ms | 10588 KB | Output is correct |
33 | Correct | 55 ms | 10584 KB | Output is correct |
34 | Correct | 56 ms | 10584 KB | Output is correct |
35 | Correct | 55 ms | 10800 KB | Output is correct |
36 | Correct | 54 ms | 10584 KB | Output is correct |
37 | Correct | 55 ms | 10588 KB | Output is correct |
38 | Correct | 44 ms | 10584 KB | Output is correct |
39 | Correct | 49 ms | 10844 KB | Output is correct |
40 | Correct | 43 ms | 10584 KB | Output is correct |
41 | Correct | 44 ms | 10584 KB | Output is correct |
42 | Correct | 45 ms | 10584 KB | Output is correct |
43 | Correct | 45 ms | 10840 KB | Output is correct |
44 | Correct | 54 ms | 10588 KB | Output is correct |
45 | Correct | 44 ms | 10584 KB | Output is correct |
46 | Correct | 43 ms | 10584 KB | Output is correct |
47 | Correct | 44 ms | 10588 KB | Output is correct |
48 | Correct | 47 ms | 10584 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 | 20 ms | 10588 KB | Output is correct |
53 | Correct | 21 ms | 10588 KB | Output is correct |
54 | Correct | 21 ms | 10800 KB | Output is correct |
55 | Correct | 20 ms | 10584 KB | Output is correct |
56 | Correct | 3 ms | 10588 KB | Output is correct |
57 | Correct | 24 ms | 10588 KB | Output is correct |
58 | Correct | 40 ms | 10840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10584 KB | Output is correct |
2 | Correct | 2 ms | 10720 KB | Output is correct |
3 | Correct | 3 ms | 10584 KB | Output is correct |
4 | Execution timed out | 5034 ms | 14456 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10584 KB | Output is correct |
2 | Correct | 1725 ms | 13056 KB | Output is correct |
3 | Correct | 2017 ms | 12980 KB | Output is correct |
4 | Correct | 2177 ms | 13292 KB | Output is correct |
5 | Correct | 36 ms | 14424 KB | Output is correct |
6 | Correct | 37 ms | 14428 KB | Output is correct |
7 | Correct | 49 ms | 14420 KB | Output is correct |
8 | Correct | 84 ms | 14420 KB | Output is correct |
9 | Correct | 215 ms | 14576 KB | Output is correct |
10 | Correct | 573 ms | 14572 KB | Output is correct |
11 | Correct | 1808 ms | 14680 KB | Output is correct |
12 | Execution timed out | 5051 ms | 14576 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | Execution timed out | 5059 ms | 12948 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10588 KB | Output is correct |
2 | Correct | 3 ms | 10584 KB | Output is correct |
3 | Correct | 2 ms | 10588 KB | Output is correct |
4 | Correct | 4 ms | 10588 KB | Output is correct |
5 | Correct | 2 ms | 10584 KB | Output is correct |
6 | Correct | 2 ms | 10584 KB | Output is correct |
7 | Correct | 2 ms | 10588 KB | Output is correct |
8 | Correct | 2 ms | 10676 KB | Output is correct |
9 | Correct | 3 ms | 10736 KB | Output is correct |
10 | Correct | 3 ms | 10588 KB | Output is correct |
11 | Correct | 3 ms | 10588 KB | Output is correct |
12 | Correct | 3 ms | 10588 KB | Output is correct |
13 | Correct | 3 ms | 10588 KB | Output is correct |
14 | Correct | 3 ms | 10588 KB | Output is correct |
15 | Correct | 3 ms | 10588 KB | Output is correct |
16 | Correct | 3 ms | 10676 KB | Output is correct |
17 | Correct | 3 ms | 10588 KB | Output is correct |
18 | Correct | 3 ms | 10680 KB | Output is correct |
19 | Correct | 3 ms | 10600 KB | Output is correct |
20 | Correct | 3 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 4 ms | 10588 KB | Output is correct |
23 | Correct | 3 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10588 KB | Output is correct |
25 | Correct | 3 ms | 10588 KB | Output is correct |
26 | Correct | 2 ms | 10588 KB | Output is correct |
27 | Correct | 2 ms | 10588 KB | Output is correct |
28 | Correct | 3 ms | 10588 KB | Output is correct |
29 | Correct | 2 ms | 10588 KB | Output is correct |
30 | Correct | 29 ms | 10588 KB | Output is correct |
31 | Correct | 34 ms | 10588 KB | Output is correct |
32 | Correct | 66 ms | 10588 KB | Output is correct |
33 | Correct | 55 ms | 10584 KB | Output is correct |
34 | Correct | 56 ms | 10584 KB | Output is correct |
35 | Correct | 55 ms | 10800 KB | Output is correct |
36 | Correct | 54 ms | 10584 KB | Output is correct |
37 | Correct | 55 ms | 10588 KB | Output is correct |
38 | Correct | 44 ms | 10584 KB | Output is correct |
39 | Correct | 49 ms | 10844 KB | Output is correct |
40 | Correct | 43 ms | 10584 KB | Output is correct |
41 | Correct | 44 ms | 10584 KB | Output is correct |
42 | Correct | 45 ms | 10584 KB | Output is correct |
43 | Correct | 45 ms | 10840 KB | Output is correct |
44 | Correct | 54 ms | 10588 KB | Output is correct |
45 | Correct | 44 ms | 10584 KB | Output is correct |
46 | Correct | 43 ms | 10584 KB | Output is correct |
47 | Correct | 44 ms | 10588 KB | Output is correct |
48 | Correct | 47 ms | 10584 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 | 20 ms | 10588 KB | Output is correct |
53 | Correct | 21 ms | 10588 KB | Output is correct |
54 | Correct | 21 ms | 10800 KB | Output is correct |
55 | Correct | 20 ms | 10584 KB | Output is correct |
56 | Correct | 3 ms | 10588 KB | Output is correct |
57 | Correct | 24 ms | 10588 KB | Output is correct |
58 | Correct | 40 ms | 10840 KB | Output is correct |
59 | Correct | 2 ms | 10584 KB | Output is correct |
60 | Correct | 2 ms | 10720 KB | Output is correct |
61 | Correct | 3 ms | 10584 KB | Output is correct |
62 | Execution timed out | 5034 ms | 14456 KB | Time limit exceeded |
63 | Halted | 0 ms | 0 KB | - |