답안 #878814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878814 2023-11-25T09:25:34 Z niter Unique Cities (JOI19_ho_t5) C++14
4 / 100
148 ms 10844 KB
#include <bits/stdc++.h>
#define pb push_back
#define ins isnert
#define pii pair<int,int>
#define ff first
#define ss second
#define loop(i,a,b) for(int i = (a); i < (b); i ++)
#define op(x) cerr << #x << " = " << x << endl;
#define opa(x) cerr << #x << " = " << x << ", ";
#define ops(x) cerr << x;
#define spac cerr << ' ';
#define entr cerr << endl;
#define STL(x) cerr << #x << " : "; for(auto &qwe:x) cerr << qwe << ' '; cerr << endl;
#define ARR(x, nnn) cerr << #x << " : "; loop(qwe,0,nnn) cerr << x[qwe] << ' '; cerr << endl;
#define BAE(x) (x).begin(), (x).end()
#define bye exit(0);
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int mxn = (int)(1e5) + 10;
vector<int> E[mxn];
int col[mxn];

vector<int> vec_col[mxn];
void dfs(int v, int par, int dis){
    vec_col[dis].pb(col[v]);
    for(auto &u:E[v]){
        if(u == par) continue;
        dfs(u, v, dis + 1);
    }
}
void test_dfs(int v, int par){
    for(auto &u:E[v]){
        if(u == par) continue;
        test_dfs(u, v);
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n, m; cin >> n >> m;
    loop(i,0,n-1){
        int a, b;
        cin >> a >> b;
        E[a].pb(b);
        E[b].pb(a);
    }
    vector<int> srt_col;
    loop(i,1,n+1){
        cin >> col[i];
        srt_col.pb(col[i]);
    }
    sort(BAE(srt_col));
    srt_col.resize(unique(BAE(srt_col)) - srt_col.begin());
    loop(i,1,n+1){
        col[i] = lower_bound(BAE(srt_col), col[i]) - srt_col.begin() + 1;
    }
    if(n > 2000){
        loop(i,1,n+1){
            test_dfs(i, -1);
        }
        return 0;
    }
    loop(i,1,n+1){
        loop(i,1,n+1) vec_col[i].clear();
        vector<int> vec_ans;
        dfs(i, -1, 0);
        loop(i,1,n+1){
            if(vec_col[i].size() == 1){
                vec_ans.pb(vec_col[i][0]);
            }
        }
        sort(BAE(vec_ans));
        vec_ans.resize(unique(BAE(vec_ans)) - vec_ans.begin());
        cout << vec_ans.size() << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 29 ms 5684 KB Output is correct
3 Correct 31 ms 5668 KB Output is correct
4 Correct 46 ms 5824 KB Output is correct
5 Correct 35 ms 5468 KB Output is correct
6 Correct 98 ms 5772 KB Output is correct
7 Correct 50 ms 5720 KB Output is correct
8 Correct 31 ms 5664 KB Output is correct
9 Correct 41 ms 5688 KB Output is correct
10 Correct 36 ms 5720 KB Output is correct
11 Correct 36 ms 5692 KB Output is correct
12 Correct 26 ms 5680 KB Output is correct
13 Correct 96 ms 5780 KB Output is correct
14 Correct 44 ms 6416 KB Output is correct
15 Correct 46 ms 6324 KB Output is correct
16 Correct 21 ms 5464 KB Output is correct
17 Correct 63 ms 8164 KB Output is correct
18 Correct 50 ms 6484 KB Output is correct
19 Correct 42 ms 5716 KB Output is correct
20 Correct 148 ms 5720 KB Output is correct
21 Correct 55 ms 5840 KB Output is correct
22 Correct 33 ms 5672 KB Output is correct
23 Correct 49 ms 5684 KB Output is correct
24 Correct 35 ms 5716 KB Output is correct
25 Correct 36 ms 5464 KB Output is correct
26 Correct 24 ms 5468 KB Output is correct
27 Correct 108 ms 5776 KB Output is correct
28 Correct 85 ms 8016 KB Output is correct
29 Correct 50 ms 6452 KB Output is correct
30 Correct 22 ms 5664 KB Output is correct
31 Correct 90 ms 8388 KB Output is correct
32 Correct 53 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 10844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 10844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 29 ms 5684 KB Output is correct
3 Correct 31 ms 5668 KB Output is correct
4 Correct 46 ms 5824 KB Output is correct
5 Correct 35 ms 5468 KB Output is correct
6 Correct 98 ms 5772 KB Output is correct
7 Correct 50 ms 5720 KB Output is correct
8 Correct 31 ms 5664 KB Output is correct
9 Correct 41 ms 5688 KB Output is correct
10 Correct 36 ms 5720 KB Output is correct
11 Correct 36 ms 5692 KB Output is correct
12 Correct 26 ms 5680 KB Output is correct
13 Correct 96 ms 5780 KB Output is correct
14 Correct 44 ms 6416 KB Output is correct
15 Correct 46 ms 6324 KB Output is correct
16 Correct 21 ms 5464 KB Output is correct
17 Correct 63 ms 8164 KB Output is correct
18 Correct 50 ms 6484 KB Output is correct
19 Correct 42 ms 5716 KB Output is correct
20 Correct 148 ms 5720 KB Output is correct
21 Correct 55 ms 5840 KB Output is correct
22 Correct 33 ms 5672 KB Output is correct
23 Correct 49 ms 5684 KB Output is correct
24 Correct 35 ms 5716 KB Output is correct
25 Correct 36 ms 5464 KB Output is correct
26 Correct 24 ms 5468 KB Output is correct
27 Correct 108 ms 5776 KB Output is correct
28 Correct 85 ms 8016 KB Output is correct
29 Correct 50 ms 6452 KB Output is correct
30 Correct 22 ms 5664 KB Output is correct
31 Correct 90 ms 8388 KB Output is correct
32 Correct 53 ms 6492 KB Output is correct
33 Runtime error 5 ms 10844 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -