QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397831#5132. House Numberingsuibian_xiaozhaoWA 170ms75076kbC++234.5kb2024-04-24 17:24:162024-04-24 17:24:17

Judging History

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

  • [2024-04-24 17:24:17]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:75076kb
  • [2024-04-24 17:24:16]
  • 提交

answer

/*

Author: Haze

2024/4/24

*/

#include <bits/stdc++.h>
//#include "test.h"

#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
using ll = long long;
#define int ll

#define debugs(x) cerr<<#x<<" "<<x<<endl;
//const int mod = 1000000000 + 7;
//const int itinf = 1000000999;
//const ll llinf = 2e18;
//const int N = 500099;
//
//3
//1 2 2
//2 3 9
//3 1 3

void solve() {
    int n;
    cin >> n;
//    vector<vector<tuple<int, int, int>>> adj(n + 1);
//    vector<vector<int>>
// to id w
    vector<vector<tuple<int, int, int>>> adj(n * 2 + 10);
    vector<set<int>> ans1(n * 2 + 10);
    vector<int> arr1(n * 2 + 10);
    vector<set<int>> ans2(n * 2 + 10);
    vector<int> arr2(n * 2 + 10);
    vector<int> vis(n * 2 + 10);
    vector<int> du(n * 2 + 10);

    for (int i = 1; i <= n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].emplace_back(v, w, i);
        adj[v].emplace_back(u, w, i);
        du[u]++;
        du[v]++;
        if (u > n)return;
        if (v > n)return;
    }
    stack<int> st;
//    debug(du);
    for (int i = 1; i <= n; i++) {
        if (du[i] == 1) {
            st.emplace(i);
        }
    }

    while (!st.empty()) {
        auto t = st.top();
        du[t]--;
//        debug(t);
        st.pop();
//        if (i > n)return;
//        if (id > n)return;
        if (t > n)return;
//        vis[t] = 1;
        for (auto [i, w, id]: adj[t]) {
            du[i]--;

            if (du[i]) {
                if (i > n)return;
                if (id > n)return;
                if (t > n)return;
                arr1[id] = t;
                ans1[t].emplace(1);
                ans1[i].emplace(w);

                arr2[id] = t;
                ans2[t].emplace(1);
                ans2[i].emplace(w);
                if (du[i] == 1)
                    st.emplace(i);
            }
        }
    }
//    debug(du);
    function<void(int, int, int)> dfs = [&](int pre, int now, int be) {
//        debug(now);
        if (now > n)return;
//        vis[now] = 1;
        for (auto [i, w, id]: adj[now]) {
            if (du[i] == 0 || i == pre) continue;
//            cerr << now << " " << i << " " << w << " " << id << endl;
            if (i > n)return;
            if (id > n)return;
//            debug(now, i, id);
            arr1[id] = now;
            ans1[now].emplace(1);
            ans1[i].emplace(w);

            arr2[id] = i;
            ans2[now].emplace(w);
            ans2[i].emplace(1);
            if (i != be) {
                dfs(now, i, be);
            }
        }
    };

    for (int i = 1; i <= n; i++) {
        if (du[i] != 0) {
            for (auto [j, w, id]: adj[i]) {
//                debug(i, j);
                if (j > n) return;
                if (id > n) return;
                if (du[j] != 0) {
                    arr1[id] = i;
                    ans1[i].emplace(1);
                    ans1[j].emplace(w);

                    arr2[id] = j;
                    ans2[i].emplace(w);
                    ans2[j].emplace(1);

                    dfs(i, j, i);
//                    debug(i, j);
//                    return;

                    bool flag = true;
                    for (int k = 1; k <= n; k++) {
                        if (ans1[k].size() != adj[k].size()) {
//                            debugs(k);
                            flag = false;
                        }
                    }
                    if (flag) {
                        for (int k = 1; k <= n; k++) {
                            cout << arr1[k] << endl;
                        }
                        return;
                    }


                    flag = true;
                    for (int k = 1; k <= n; k++) {
                        if (ans2[k].size() != adj[k].size()) {
//                            debugs(k);
                            flag = false;
                        }
                    }
                    if (flag) {
                        for (int k = 1; k <= n; k++) {
                            cout << arr2[k] << endl;
                        }
                        return;
                    }

                    cout << "impossible" << endl;
                    return;
                }
            }
            return;
        }
    }


}

signed main() {
//    IOS
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3856kb

input:

3
1 2 2
2 3 9
3 1 3

output:

1
2
3

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

4
1 2 2
1 3 2
2 3 2
1 4 2

output:

impossible

result:

ok 

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3
3 2 2
2 1 2
1 3 2

output:

2
1
3

result:

ok 

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

3
1 3 374
3 2 519
2 1 549

output:

1
3
2

result:

ok 

Test #5:

score: 0
Accepted
time: 0ms
memory: 4316kb

input:

1000
960 606 2
606 278 2
278 118 2
118 965 2
965 546 2
546 518 2
518 758 2
758 32 2
32 839 2
839 245 2
245 201 2
201 353 2
353 386 2
386 737 2
737 420 2
420 838 2
838 493 2
493 905 2
905 704 2
704 563 2
563 687 2
687 218 2
218 739 2
739 544 2
544 548 2
548 442 2
442 744 2
744 724 2
724 640 2
640 767...

output:

606
278
118
965
546
518
758
32
839
245
201
353
386
737
420
838
493
905
704
563
687
218
739
544
548
442
744
724
640
767
816
164
154
231
211
788
686
599
715
410
759
521
121
585
148
158
854
603
344
966
242
458
852
709
592
880
902
629
680
867
469
703
957
84
396
509
319
942
972
238
358
932
692
145
847
94...

result:

ok 

Test #6:

score: 0
Accepted
time: 0ms
memory: 4520kb

input:

1000
758 943 361
943 940 927
940 267 37
267 932 61
932 503 811
503 851 961
851 759 727
759 553 953
553 327 963
327 766 814
766 146 790
146 219 456
219 751 418
751 594 395
594 355 506
355 800 556
800 487 448
487 154 412
154 152 12
152 418 767
418 538 525
538 353 651
353 964 296
964 346 516
346 139 14...

output:

943
940
267
932
503
851
759
553
327
766
146
219
751
594
355
800
487
154
152
418
538
353
964
346
139
6
527
485
836
814
24
118
537
603
409
573
589
848
492
394
973
960
279
955
531
291
611
995
864
384
632
464
870
507
561
968
583
969
432
404
510
296
840
285
998
141
727
637
466
802
477
111
592
630
434
793...

result:

ok 

Test #7:

score: 0
Accepted
time: 7ms
memory: 10292kb

input:

10000
3186 2782 2
2782 298 2
298 5102 2
5102 7844 2
7844 2121 2
2121 1327 2
1327 963 2
963 1476 2
1476 6796 2
6796 2601 2
2601 3663 2
3663 537 2
537 7009 2
7009 8359 2
8359 9182 2
9182 3559 2
3559 2818 2
2818 3174 2
3174 1350 2
1350 3944 2
3944 4620 2
4620 7832 2
7832 7007 2
7007 8636 2
8636 131 2
1...

output:

2782
298
5102
7844
2121
1327
963
1476
6796
2601
3663
537
7009
8359
9182
3559
2818
3174
1350
3944
4620
7832
7007
8636
131
1774
2430
2023
4765
599
1384
7695
6664
5795
7263
2886
4772
1005
9465
4003
7943
5695
8458
9611
8537
1365
4295
9147
7347
4046
4230
6230
6636
7518
8450
1611
6158
5896
9895
8102
6003
...

result:

ok 

Test #8:

score: 0
Accepted
time: 14ms
memory: 10384kb

input:

10000
3852 8753 857
8753 6570 997
6570 8378 337
8378 6838 253
6838 6832 801
6832 1443 879
1443 5821 206
5821 9332 690
9332 481 638
481 4466 88
4466 9433 464
9433 1713 258
1713 5136 243
5136 1300 962
1300 4261 200
4261 599 974
599 6852 651
6852 7430 162
7430 6058 474
6058 1914 235
1914 6049 128
6049 ...

output:

8753
6570
8378
6838
6832
1443
5821
9332
481
4466
9433
1713
5136
1300
4261
599
6852
7430
6058
1914
6049
3935
9278
8520
3551
5041
4622
8693
4680
6652
2051
7185
6381
9164
7385
9627
7285
2680
3167
141
8850
9498
8900
1510
5471
2901
7697
5285
8881
6603
7404
1217
6444
6526
6581
6681
2582
7581
8204
3165
594...

result:

ok 

Test #9:

score: 0
Accepted
time: 115ms
memory: 75076kb

input:

100000
49761 50860 2
50860 76368 2
76368 36060 2
36060 38900 2
38900 8477 2
8477 16539 2
16539 1834 2
1834 41645 2
41645 11420 2
11420 52011 2
52011 70194 2
70194 5318 2
5318 90571 2
90571 25209 2
25209 36177 2
36177 83455 2
83455 97871 2
97871 76892 2
76892 50332 2
50332 70903 2
70903 94195 2
94195...

output:

50860
76368
36060
38900
8477
16539
1834
41645
11420
52011
70194
5318
90571
25209
36177
83455
97871
76892
50332
70903
94195
61933
31177
21238
74820
99490
26047
31858
62948
29778
16892
94302
43724
37400
7932
2470
72838
51206
80051
39672
58583
92664
52368
19444
65620
76657
6056
6878
13492
61144
82351
2...

result:

ok 

Test #10:

score: 0
Accepted
time: 135ms
memory: 74968kb

input:

100000
99597 2401 4114
2401 31522 8636
31522 5447 6268
5447 81737 4594
81737 33124 9354
33124 45703 4433
45703 11371 2069
11371 32023 3251
32023 75309 630
75309 41612 2093
41612 72484 2539
72484 68595 4051
68595 26179 3927
26179 32505 2939
32505 14017 7967
14017 41000 8122
41000 44698 9268
44698 135...

output:

2401
31522
5447
81737
33124
45703
11371
32023
75309
41612
72484
68595
26179
32505
14017
41000
44698
13554
81437
38670
29915
4115
11545
96469
82271
25158
40706
64753
16741
29158
27028
68763
67221
3642
20953
1842
44974
18774
77786
74748
32518
18966
94057
17449
81693
77323
66374
53595
14432
2837
57199
...

result:

ok 

Test #11:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

10
6 4 2
4 3 2
3 6 2
6 1 3
6 2 4
6 9 5
6 10 6
6 5 7
6 7 8
6 8 8

output:

impossible

result:

ok 

Test #12:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

10
5 3 2
3 8 2
8 5 2
5 2 3
5 6 4
5 7 5
5 9 6
5 1 7
5 4 8
5 10 9

output:

3
8
5
2
6
7
9
1
4
10

result:

ok 

Test #13:

score: 0
Accepted
time: 11ms
memory: 8556kb

input:

10000
960 7551 2
7551 6364 2
6364 960 2
960 5654 3
960 2576 4
960 3869 5
960 4041 6
960 8097 7
960 5925 8
960 8942 9
960 7956 10
960 5679 11
960 7926 12
960 7225 13
960 1441 14
960 9198 15
960 2728 16
960 5234 17
960 9504 18
960 5978 19
960 8617 20
960 4722 21
960 9776 22
960 1438 23
960 8510 24
960...

output:

impossible

result:

ok 

Test #14:

score: 0
Accepted
time: 8ms
memory: 8732kb

input:

10000
6892 5836 2
5836 8076 2
8076 6892 2
6892 41 3
6892 818 4
6892 1869 5
6892 9971 6
6892 8893 7
6892 8448 8
6892 8797 9
6892 4734 10
6892 6363 11
6892 2521 12
6892 6653 13
6892 6429 14
6892 9183 15
6892 4574 16
6892 6263 17
6892 5796 18
6892 8647 19
6892 6395 20
6892 1067 21
6892 9777 22
6892 459...

output:

5836
8076
6892
41
818
1869
9971
8893
8448
8797
4734
6363
2521
6653
6429
9183
4574
6263
5796
8647
6395
1067
9777
4595
235
5635
927
8834
1912
6402
2966
432
6508
5806
4877
907
2615
458
8254
1818
8999
8443
3380
4498
1173
9423
3712
2489
8615
3964
6068
3738
9939
5056
3577
9267
1710
4952
8510
1809
953
1476...

result:

ok 

Test #15:

score: 0
Accepted
time: 153ms
memory: 57144kb

input:

100000
84225 28140 2
28140 64081 2
64081 84225 2
84225 3607 3
84225 79098 4
84225 54956 5
84225 56652 6
84225 10188 7
84225 71334 8
84225 28446 9
84225 54343 10
84225 16085 11
84225 8783 12
84225 48459 13
84225 56054 14
84225 71712 15
84225 76633 16
84225 35106 17
84225 41707 18
84225 21811 19
84225...

output:

impossible

result:

ok 

Test #16:

score: 0
Accepted
time: 170ms
memory: 57180kb

input:

100000
91433 48183 2
48183 98573 2
98573 91433 2
91433 20844 3
91433 52909 4
91433 64002 5
91433 34038 6
91433 14470 7
91433 8314 8
91433 86980 9
91433 44958 10
91433 80520 11
91433 17505 12
91433 68805 13
91433 48074 14
91433 98859 15
91433 16335 16
91433 52854 17
91433 40979 18
91433 82430 19
9143...

output:

48183
98573
91433
20844
52909
64002
34038
14470
8314
86980
44958
80520
17505
68805
48074
98859
16335
52854
40979
82430
49499
45108
83352
70703
8792
7553
83587
3230
99710
56070
34020
639
43646
98027
26327
65143
64023
49213
59721
98883
94961
92239
53016
99598
63728
61644
27760
27782
60713
45856
80862
...

result:

ok 

Test #17:

score: 0
Accepted
time: 119ms
memory: 66212kb

input:

100000
4643 71477 2
71477 78529 2
78529 97642 2
97642 88636 2
88636 19946 2
19946 11925 2
11925 2648 2
2648 7214 2
7214 90083 2
90083 39222 2
39222 79070 2
79070 69444 2
69444 36168 2
36168 4265 2
4265 57132 2
57132 12498 2
12498 47674 2
47674 92898 2
92898 98727 2
98727 36767 2
36767 73724 2
73724 ...

output:

impossible

result:

ok 

Test #18:

score: 0
Accepted
time: 143ms
memory: 66072kb

input:

100000
57159 6315 2
6315 95767 2
95767 55984 2
55984 54114 2
54114 91071 2
91071 85044 2
85044 5160 2
5160 59261 2
59261 72861 2
72861 99866 2
99866 80777 2
80777 9040 2
9040 89828 2
89828 29646 2
29646 13953 2
13953 34849 2
34849 90489 2
90489 74896 2
74896 85077 2
85077 58369 2
58369 59655 2
59655...

output:

6315
95767
55984
54114
91071
85044
5160
59261
72861
99866
80777
9040
89828
29646
13953
34849
90489
74896
85077
58369
59655
45430
82354
70328
43180
87429
12105
6756
78957
29966
99968
40349
16161
58825
76325
89471
48132
46683
87118
93739
14093
16090
97019
65189
50496
32412
78286
55054
39959
34040
9401...

result:

ok 

Test #19:

score: 0
Accepted
time: 127ms
memory: 73372kb

input:

100000
69460 3866 2
3866 96896 2
96896 72257 2
72257 45458 2
45458 70526 2
70526 98548 2
98548 91978 2
91978 22460 2
22460 76384 2
76384 13354 2
13354 65620 2
65620 39774 2
39774 39579 2
39579 86381 2
86381 69224 2
69224 88209 2
88209 68771 2
68771 87959 2
87959 73484 2
73484 9506 2
9506 20048 2
200...

output:

impossible

result:

ok 

Test #20:

score: 0
Accepted
time: 123ms
memory: 73296kb

input:

100000
25768 64056 2
64056 92930 2
92930 83257 2
83257 43237 2
43237 43215 2
43215 97503 2
97503 60742 2
60742 42794 2
42794 67658 2
67658 55721 2
55721 439 2
439 29059 2
29059 46455 2
46455 29253 2
29253 23747 2
23747 89873 2
89873 93582 2
93582 25689 2
25689 40564 2
40564 37314 2
37314 67040 2
670...

output:

64056
92930
83257
43237
43215
97503
60742
42794
67658
55721
439
29059
46455
29253
23747
89873
93582
25689
40564
37314
67040
578
88015
75945
78540
95394
12413
28451
1370
85685
9843
13929
66925
8616
31408
78954
89678
45490
26008
77312
6253
66387
53176
95418
63217
65029
34445
57418
45276
44933
93888
39...

result:

ok 

Test #21:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

4
1 2 2
2 3 2
3 1 2
4 1 2

output:

impossible

result:

ok 

Test #22:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4
2 3 10
3 1 189
1 2 9
4 2 187

output:

3
1
2
4

result:

ok 

Test #23:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

40
32 25 2
25 18 2
18 4 2
4 26 2
26 11 2
11 37 2
37 9 2
9 5 2
5 36 2
36 3 2
3 31 2
31 28 2
28 39 2
39 12 2
12 16 2
16 15 2
15 20 2
20 19 2
19 40 2
40 32 2
24 19 2
38 39 2
33 31 2
30 33 2
8 33 2
6 8 2
35 36 2
7 36 2
22 8 2
10 32 2
29 19 2
27 20 2
34 11 2
1 28 2
2 26 2
23 19 2
17 8 2
21 7 2
13 2 2
14 ...

output:

impossible

result:

ok 

Test #24:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

40
32 30 3
30 23 3
23 28 2
28 9 3
9 2 2
2 4 3
4 19 2
19 15 2
15 11 2
11 8 2
8 24 3
24 6 2
6 1 2
1 3 2
3 39 2
39 38 3
38 35 2
35 18 3
18 37 3
37 32 2
25 35 3
12 25 3
29 19 3
7 28 3
36 19 2
17 3 2
16 24 3
31 15 2
27 23 2
14 12 2
10 1 2
21 11 3
34 18 2
20 27 3
26 32 2
13 12 2
33 12 2
40 8 2
5 37 3
22 3...

output:

impossible

result:

ok 

Test #25:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

40
38 28 4
28 18 4
18 4 4
4 15 6
15 8 6
8 40 6
40 20 2
20 33 5
33 32 3
32 2 5
2 21 2
21 22 4
22 24 5
24 14 5
14 11 2
11 30 5
30 34 5
34 17 2
17 39 3
39 38 3
23 15 6
10 4 3
5 18 3
26 2 4
3 38 3
27 3 4
6 2 2
19 32 5
12 21 2
31 19 2
29 30 3
25 24 4
35 14 5
37 24 2
7 10 5
1 2 4
9 26 4
36 37 6
16 17 5
13...

output:

impossible

result:

ok 

Test #26:

score: -100
Wrong Answer
time: 1ms
memory: 3636kb

input:

40
32 9 265
9 1 377
1 30 203
30 26 554
26 35 434
35 11 397
11 6 300
6 36 218
36 17 352
17 19 312
19 39 417
39 4 51
4 22 167
22 12 79
12 24 78
24 18 100
18 14 266
14 37 63
37 34 92
34 32 327
40 36 474
10 17 589
25 22 133
20 35 374
15 18 547
8 34 334
23 8 218
27 25 591
28 22 129
21 23 325
31 20 306
29...

output:

impossible

result:

wrong output format Expected integer, but "impossible" found