QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768084#2766. Unique Cities_8_8_0 919ms172440kbC++203.1kb2024-11-21 00:24:002024-11-21 00:24:00

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 00:24:00]
  • 评测
  • 测评结果:0
  • 用时:919ms
  • 内存:172440kb
  • [2024-11-21 00:24:00]
  • 提交

answer

#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
    
const int  N = (1 << 20) + 12, MOD = (int)1e9 + 7;

int n, m, a[N], vis[N], timer, p[N];
vector<int> g[N], gt[N];
bool is[N];
map<int, int> dist[N];
int f(int d) {
    timer++;
    vis[d] = timer;
    int lst = d;
    queue<int> q;
    q.push(d);
    dist[d][d] = 0;
    while(!q.empty()) {
        int v = q.front();
        lst = v;
        q.pop();
        for(int to : g[v]) {
            if(vis[to] != timer) {
                dist[d][to] = dist[d][v] + 1;
                q.push(to);
                vis[to] = timer;
            }
        }
    }
    return lst;
}
int col[N], dep[N], mxd[N], res[N], d, d1, o, cr;
int zap = 0;
bool ok[N];
void dfs(int v, int pr = -1) {
    mxd[v] = dep[v];
    for(int to:g[v]) if(to != pr) {
        gt[v].push_back(to);
        dep[to] = dep[v] + 1;
        dfs(to, v);
        mxd[v] = max(mxd[v], mxd[to]);
    }
    for(int i = 0; i < (int)gt[v].size(); i++) {
        if(mxd[gt[v][i]] == mxd[v]) {
            swap(gt[v][0], gt[v][i]);
        }
    }
}

vector<int> st;
void go(int v) {
    if(dist[cr][v] > dist[o][v] || (dist[cr][v] == dist[o][v] && zap)) {
        // set<int> raz;
        for(int i = 0; i < (int)st.size() && mxd[v] - dep[v] < dep[v] - dep[st[i]]; i++) {
            // raz.insert(a[st[i]]);
            res[v]++;
            break;
        }
        // res[v] += (int)raz.size();
    }
    if(gt[v].empty()) return;
    int sz = (int)gt[v].size();
    vector<int> p(sz), s(sz);
    p[0] = mxd[gt[v][0]];
    s[sz - 1] = mxd[gt[v][sz - 1]];
    for(int i = 1; i < sz; i++) {
        p[i] = max(p[i - 1], mxd[gt[v][i]]);
    }
    for(int i = sz - 2; i >= 0; i--) {
        s[i] = max(s[i + 1], mxd[gt[v][i]]);
    }
    vector<int> del;
    for(int i = 0; i < sz; i++) {
        int to = gt[v][i];
        int mx = dep[v];
        if(i) mx = max(mx, p[i - 1]);
        if(i < sz - 1) mx = max(mx, s[i + 1]);
        mx -= dep[v];
        if(i == 1) st.pop_back();
        if(i <= 1) {
            while(!st.empty() && dep[v] - dep[st.back()] <= mx) {
                del.push_back(st.back());
                st.pop_back();
            }
        }
        if(i <= 1) st.push_back(v);
        go(to);
    }
    st.pop_back();
    reverse(del.begin(), del.end());
    for(int j:del) {
        st.push_back(j);
    }
}
void solve(int root) {
    for(int i = 1; i <= n; i++) {
        gt[i].clear();
    }
    st.clear();
    dep[root] = 1;
    dfs(root);

    go(root);
}
void test() {
    cin >> n >> m;
    for(int i = 1; i <= n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    d = f(1), d1 = f(d);
    f(d1);
    o = d1;cr = d;
    solve(d);
    zap = 1;
    o = d;cr = d1;
    solve(d1);
    for(int i = 1; i <= n; i++) {
        cout << res[i] << '\n';
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1; 
    // cin >> t;

    while(t--) 
        test();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 4ms
memory: 62912kb

input:

2 1
1 2
1 1

output:

1
1

result:

ok 2 lines

Test #2:

score: 0
Wrong Answer
time: 12ms
memory: 61368kb

input:

1842 848
740 1093
1299 922
801 1560
265 1664
1043 65
1430 427
80 233
4 1238
1623 1473
1569 274
953 1485
1259 649
1671 1409
246 542
742 1517
720 1120
1527 1328
1167 1531
1056 1130
673 1222
192 980
1393 913
446 688
135 23
1065 1787
978 1481
1765 1720
310 202
1406 1451
475 523
104 774
1531 829
169 396
...

output:

1
1
1
0
0
0
1
0
1
0
1
1
0
1
0
0
0
1
0
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
0
0
1
1
0
1
1
0
1
1
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
0
1
0
1
1
0
0
1
0
0
0
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
0
0
0
1
0
1
1
1
1
1
1
0
1
1
1
1
0
1
1
0
0
1
0
1
0
1
1
0
1
0
1
0
1
0
0
1
0
1
0
1
...

result:

wrong answer 7th lines differ - expected: '2', found: '1'

Subtask #2:

score: 0
Time Limit Exceeded

Test #33:

score: 32
Accepted
time: 420ms
memory: 89600kb

input:

115391 1
32067 50006
1710 5850
21016 66364
72998 34367
24783 10670
49950 93666
81835 81234
53480 68963
87357 43320
93905 30509
72528 92224
520 100511
54804 2917
58490 23858
93643 87530
90737 65205
60740 110812
9553 90266
70028 67222
108045 88982
35584 110286
53518 21733
108735 26404
108228 109796
92...

output:

1
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
0
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 115391 lines

Test #34:

score: 32
Accepted
time: 389ms
memory: 125308kb

input:

114976 1
74053 36053
62978 89255
32367 21913
113882 44280
60815 35782
107811 95272
109039 78845
22484 41688
1781 111596
111506 59375
19869 45586
84990 81214
38638 90205
14928 14370
10758 5465
87745 5949
66720 6357
76134 26466
91805 105936
31792 68220
74216 108462
60158 67410
69489 50297
74956 63776
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 114976 lines

Test #35:

score: 32
Accepted
time: 75ms
memory: 72316kb

input:

28388 1
10509 15648
25863 14495
26973 2553
22819 7801
5054 15080
6091 12384
4727 3538
14600 14672
4481 9533
26520 23761
6729 3525
15678 8426
7628 26890
25846 26267
10186 5633
21692 25057
17882 26693
25518 13361
6875 371
27786 23632
24474 21637
1387 8015
22050 3422
8420 25752
26814 7209
11499 21112
5...

output:

1
1
1
0
1
0
0
0
0
0
0
1
0
0
0
0
1
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
1
1
0
1
0
1
1
1
0
1
1
0
1
0
1
1
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
1
1
0
1
1
0
1
1
1
0
0
1
1
0
1
0
0
1
1
0
1
0
0
0
0
1
0
1
1
0
0
0
1
0
1
0
0
1
1
0
1
1
0
0
0
0
1
1
0
1
1
0
0
0
0
1
1
0
0
1
1
1
1
0
1
0
0
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
...

result:

ok 28388 lines

Test #36:

score: 32
Accepted
time: 865ms
memory: 110560kb

input:

200000 1
17564 189544
118109 130056
39153 56739
138814 48828
103560 16598
174399 8469
146229 189678
173046 95721
168793 168656
21067 78280
169301 178753
63496 153947
22754 181712
34926 22205
41248 16310
81136 35768
87905 3442
89999 119217
108408 136055
153855 175444
177272 157293
174568 5857
71023 5...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #37:

score: 32
Accepted
time: 881ms
memory: 172440kb

input:

200000 1
35713 32997
199904 59024
24108 108224
75623 8060
169202 44171
166898 189166
52691 184504
91052 94474
3355 161889
76684 4006
13328 59307
83889 5391
139095 198059
194946 197068
147175 102095
68329 10784
45563 111710
123071 177610
156268 186570
149699 52604
191299 78685
68117 130476
132359 860...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #38:

score: 32
Accepted
time: 919ms
memory: 147208kb

input:

200000 1
15065 142612
651 173717
153862 68423
150849 147717
192561 152722
165359 180378
34627 59508
140908 24495
180671 177962
183330 27822
155654 53394
20596 1741
76236 52151
167441 5306
73654 149981
97720 142937
10793 84081
124721 123748
185212 150311
170407 158310
125015 73861
36456 121189
39975 ...

output:

1
0
1
1
0
0
1
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
0
1
0
1
1
0
1
1
0
1
0
1
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
0
0
1
1
0
0
0
0
0
0
0
0
1
0
1
0
0
1
1
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
0
0
1
0
0
0
1
1
1
1
0
1
0
0
1
1
0
0
0
1
...

result:

ok 200000 lines

Test #39:

score: 32
Accepted
time: 828ms
memory: 112588kb

input:

200000 1
86027 61282
69968 35175
136022 154753
52733 39599
97774 24158
25263 138562
112124 6412
183205 101112
112094 38819
113526 47859
137031 122132
165018 84375
76900 182974
29302 174006
34918 73123
23660 37001
141115 33742
61282 24152
150734 61282
22552 49677
106054 193519
84741 62724
6470 178907...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #40:

score: 32
Accepted
time: 900ms
memory: 122676kb

input:

200000 1
28426 75100
141794 24004
167055 168353
178427 10860
34348 190354
192106 81422
75263 134731
54229 108154
90586 122196
172392 58237
84932 15421
79435 77253
185144 24679
63387 23340
68674 72825
137398 109447
33249 46900
99738 44920
92707 125920
163133 64180
83887 123053
152655 83838
133345 953...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #41:

score: 32
Accepted
time: 903ms
memory: 120548kb

input:

200000 1
69183 39245
163717 95756
76286 79561
100403 156730
144012 28043
198819 127959
64878 40226
57715 170431
64896 172859
44376 76276
154716 52042
193460 121983
98422 173076
114307 113862
51895 51986
193923 26201
116458 6275
6786 5649
175035 64551
148902 26238
129547 45157
151907 50571
76031 8614...

output:

1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #42:

score: 32
Accepted
time: 864ms
memory: 114548kb

input:

200000 1
196045 146636
176533 42271
166724 196028
139244 76615
148314 148067
178418 115890
192238 183829
32675 57585
185089 143473
101515 59837
190250 186401
150802 188721
50798 191609
47863 142815
183786 28970
184954 58810
13430 196707
133210 193546
49302 49747
109810 162864
98935 133593
169908 210...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #43:

score: 32
Accepted
time: 710ms
memory: 109620kb

input:

200000 1
58527 148510
90024 104304
46291 148510
148510 193006
51631 148510
148510 117266
148510 53357
166103 148510
148510 127112
148510 105363
148510 171703
56809 148510
148510 60920
164837 148510
148510 181377
67076 148510
148510 94358
8910 148510
43101 148510
148510 64867
148510 46788
148510 4249...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #44:

score: 0
Time Limit Exceeded

input:

200000 1
66730 123320
47115 79350
85283 171708
156551 17983
140238 171549
93983 190883
146694 145897
48194 48325
186569 69965
165293 107104
105458 137156
117295 132479
49962 144513
135589 103731
120064 134791
163864 155625
175728 67758
190171 179156
102382 51967
50807 154114
8247 142134
101115 87765...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #50:

score: 0
Wrong Answer
time: 637ms
memory: 100284kb

input:

157976 157976
20171 157173
44732 54119
107845 121149
109200 110309
82678 108206
89140 64200
36916 128759
3966 123760
92978 105716
43700 146126
14924 3429
107721 36095
94906 78173
97162 29552
119574 39605
25145 138492
16622 99431
60281 7949
76176 136644
75716 91518
127987 110605
77999 110960
101187 5...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 2nd lines differ - expected: '5', found: '1'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%