답안 #132343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132343 2019-07-18T17:57:09 Z duality Construction of Highway (JOI18_construction) C++11
16 / 100
2000 ms 16188 KB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int C[100000];
vi adjList[100000];
int parent[100000],order[100000];
int depth[100000];
int disc[100000],fin[100000],inv[100000],num = 0;
int doDFS(int u,int d) {
    int i;
    depth[u] = d,disc[u] = num++,inv[num-1] = u;
    for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i],d+1);
    fin[u] = num;
    return 0;
}
int good[100000],pref[100000];
int main() {
    int i;
    int N,A,B;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&C[i]);
    parent[0] = -1;
    for (i = 0; i < N-1; i++) {
        scanf("%d %d",&A,&B);
        A--,B--;
        adjList[A].pb(B),parent[B] = A;
        order[i] = B;
    }
    doDFS(0,0);

    int j,k;
    for (i = 0; i < N; i++) pref[i] = -1;
    for (i = 0; i < N-1; i++) {
        int u = order[i];
        vpii vv;
        while (u != 0) {
            int v = pref[parent[u]];
            if (v != -1) good[v] = 0;
            pref[parent[u]] = u,good[u] = 1;
            int w = parent[u];
            while (good[w]) w = parent[w];
            if (v != -1) C[v] = C[w];
            vv.pb(mp(C[w],depth[u]-depth[w]));
            u = w;
        }
        LLI ans = 0;
        reverse(vv.begin(),vv.end());
        for (j = 0; j < vv.size(); j++) {
            for (k = j+1; k < vv.size(); k++) {
                if (vv[j].first > vv[k].first) ans += (LLI) vv[j].second*vv[k].second;
            }
        }
        printf("%lld\n",ans);
        C[0] = C[order[i]];
    }

    return 0;
}

Compilation message

construction.cpp: In function 'int doDFS(int, int)':
construction.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i],d+1);
                 ~~^~~~~~~~~~~~~~~~~~~
construction.cpp: In function 'int main()':
construction.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < vv.size(); j++) {
                     ~~^~~~~~~~~~~
construction.cpp:55:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k = j+1; k < vv.size(); k++) {
                           ~~^~~~~~~~~~~
construction.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
construction.cpp:27:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d",&C[i]);
                             ~~~~~^~~~~~~~~~~~
construction.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&A,&B);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 5 ms 2752 KB Output is correct
6 Correct 4 ms 2656 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 5 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2808 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2808 KB Output is correct
24 Correct 4 ms 2808 KB Output is correct
25 Correct 4 ms 2808 KB Output is correct
26 Correct 5 ms 2808 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2780 KB Output is correct
31 Correct 5 ms 2808 KB Output is correct
32 Correct 5 ms 2808 KB Output is correct
33 Correct 4 ms 2808 KB Output is correct
34 Correct 5 ms 2808 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2808 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 4 ms 2680 KB Output is correct
40 Correct 4 ms 2680 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 4 ms 2680 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 5 ms 2752 KB Output is correct
6 Correct 4 ms 2656 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 5 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2808 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2808 KB Output is correct
24 Correct 4 ms 2808 KB Output is correct
25 Correct 4 ms 2808 KB Output is correct
26 Correct 5 ms 2808 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2780 KB Output is correct
31 Correct 5 ms 2808 KB Output is correct
32 Correct 5 ms 2808 KB Output is correct
33 Correct 4 ms 2808 KB Output is correct
34 Correct 5 ms 2808 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2808 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 4 ms 2680 KB Output is correct
40 Correct 4 ms 2680 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 4 ms 2680 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2808 KB Output is correct
45 Correct 5 ms 2808 KB Output is correct
46 Correct 8 ms 2936 KB Output is correct
47 Correct 8 ms 2936 KB Output is correct
48 Correct 8 ms 3064 KB Output is correct
49 Correct 25 ms 3196 KB Output is correct
50 Correct 26 ms 3192 KB Output is correct
51 Correct 26 ms 3320 KB Output is correct
52 Correct 18 ms 3064 KB Output is correct
53 Correct 24 ms 3192 KB Output is correct
54 Correct 23 ms 3192 KB Output is correct
55 Correct 24 ms 3192 KB Output is correct
56 Correct 17 ms 3064 KB Output is correct
57 Correct 9 ms 2936 KB Output is correct
58 Correct 10 ms 3064 KB Output is correct
59 Correct 10 ms 3064 KB Output is correct
60 Correct 10 ms 3064 KB Output is correct
61 Correct 17 ms 3064 KB Output is correct
62 Correct 17 ms 3064 KB Output is correct
63 Correct 17 ms 3064 KB Output is correct
64 Correct 8 ms 2936 KB Output is correct
65 Correct 8 ms 2936 KB Output is correct
66 Correct 8 ms 3064 KB Output is correct
67 Correct 8 ms 2936 KB Output is correct
68 Correct 26 ms 3192 KB Output is correct
69 Correct 19 ms 3192 KB Output is correct
70 Correct 76 ms 3064 KB Output is correct
71 Correct 18 ms 3064 KB Output is correct
72 Correct 9 ms 2936 KB Output is correct
73 Correct 10 ms 2936 KB Output is correct
74 Correct 17 ms 3064 KB Output is correct
75 Correct 12 ms 3064 KB Output is correct
76 Correct 10 ms 2936 KB Output is correct
77 Correct 10 ms 3064 KB Output is correct
78 Correct 12 ms 2936 KB Output is correct
79 Correct 10 ms 2936 KB Output is correct
80 Correct 9 ms 3064 KB Output is correct
81 Correct 12 ms 3064 KB Output is correct
82 Correct 11 ms 3064 KB Output is correct
83 Correct 10 ms 3064 KB Output is correct
84 Correct 13 ms 3020 KB Output is correct
85 Correct 11 ms 3064 KB Output is correct
86 Correct 10 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 5 ms 2752 KB Output is correct
6 Correct 4 ms 2656 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 5 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2808 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2808 KB Output is correct
24 Correct 4 ms 2808 KB Output is correct
25 Correct 4 ms 2808 KB Output is correct
26 Correct 5 ms 2808 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2780 KB Output is correct
31 Correct 5 ms 2808 KB Output is correct
32 Correct 5 ms 2808 KB Output is correct
33 Correct 4 ms 2808 KB Output is correct
34 Correct 5 ms 2808 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2808 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 4 ms 2680 KB Output is correct
40 Correct 4 ms 2680 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 4 ms 2680 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2808 KB Output is correct
45 Correct 5 ms 2808 KB Output is correct
46 Correct 8 ms 2936 KB Output is correct
47 Correct 8 ms 2936 KB Output is correct
48 Correct 8 ms 3064 KB Output is correct
49 Correct 25 ms 3196 KB Output is correct
50 Correct 26 ms 3192 KB Output is correct
51 Correct 26 ms 3320 KB Output is correct
52 Correct 18 ms 3064 KB Output is correct
53 Correct 24 ms 3192 KB Output is correct
54 Correct 23 ms 3192 KB Output is correct
55 Correct 24 ms 3192 KB Output is correct
56 Correct 17 ms 3064 KB Output is correct
57 Correct 9 ms 2936 KB Output is correct
58 Correct 10 ms 3064 KB Output is correct
59 Correct 10 ms 3064 KB Output is correct
60 Correct 10 ms 3064 KB Output is correct
61 Correct 17 ms 3064 KB Output is correct
62 Correct 17 ms 3064 KB Output is correct
63 Correct 17 ms 3064 KB Output is correct
64 Correct 8 ms 2936 KB Output is correct
65 Correct 8 ms 2936 KB Output is correct
66 Correct 8 ms 3064 KB Output is correct
67 Correct 8 ms 2936 KB Output is correct
68 Correct 26 ms 3192 KB Output is correct
69 Correct 19 ms 3192 KB Output is correct
70 Correct 76 ms 3064 KB Output is correct
71 Correct 18 ms 3064 KB Output is correct
72 Correct 9 ms 2936 KB Output is correct
73 Correct 10 ms 2936 KB Output is correct
74 Correct 17 ms 3064 KB Output is correct
75 Correct 12 ms 3064 KB Output is correct
76 Correct 10 ms 2936 KB Output is correct
77 Correct 10 ms 3064 KB Output is correct
78 Correct 12 ms 2936 KB Output is correct
79 Correct 10 ms 2936 KB Output is correct
80 Correct 9 ms 3064 KB Output is correct
81 Correct 12 ms 3064 KB Output is correct
82 Correct 11 ms 3064 KB Output is correct
83 Correct 10 ms 3064 KB Output is correct
84 Correct 13 ms 3020 KB Output is correct
85 Correct 11 ms 3064 KB Output is correct
86 Correct 10 ms 3064 KB Output is correct
87 Correct 15 ms 3448 KB Output is correct
88 Correct 43 ms 4984 KB Output is correct
89 Correct 162 ms 10104 KB Output is correct
90 Correct 162 ms 9936 KB Output is correct
91 Correct 158 ms 9976 KB Output is correct
92 Execution timed out 2064 ms 16188 KB Time limit exceeded
93 Halted 0 ms 0 KB -