QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765167#5337. Making FriendsMispertion100 ✓175ms47760kbC++232.1kb2024-11-20 12:50:242024-11-20 12:50:24

Judging History

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

  • [2024-11-20 12:50:24]
  • 评测
  • 测评结果:100
  • 用时:175ms
  • 内存:47760kb
  • [2024-11-20 12:50:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define int ll
using ld = long double;
using pii = pair<int, int>;

#define F first
#define S second

const ld PI = 3.1415926535;
const int N = 2e5 + 5;
const int M = 1e7 + 1;
ll mod;
const int infi = 1e9;
const ll infl = 1e16;
const int P = 31;

int mult(int a, int b) { return a * 1LL * b % mod; }

int sum(int a, int b) {
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}

ll binpow(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % (mod + 1);
    } else {
        ll b = binpow(a, n / 2);
        return b * b % (mod + 1);
    }
}

int n, m, p[N], sz[N];
set<int> st[N];
vector<int> g[N];

int getp(int v){
    if(p[v] == v)
        return v;
    return p[v] = getp(p[v]);
}

void uni(int a, int b){
    a = getp(a);
    b = getp(b);
    if(a == b)
        return;
    if(sz[a] > sz[b])
        swap(a, b);
    sz[b] += sz[a];
    p[a] = b;
    if(st[a].size() > st[b].size()){
        for(auto e : st[b])
            st[a].insert(e);
        st[b].swap(st[a]);
    }else{
        for(auto e : st[a])
            st[b].insert(e);
    }
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        p[i] = i;
        sz[i] = 1;
        for(auto e : g[i])
            if(e > i)
                st[i].insert(e);
        for(auto e : g[i]){
            if(e < i)
                uni(e, i);
        }
        int v = getp(i);
        st[v].erase(i);
        ans += st[v].size();
        for(auto e : g[i])
            if(e > i && st[v].find(e) != st[v].end())
                ans--;
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5.88235
Accepted
time: 0ms
memory: 15888kb

input:

7 6
1 3
1 4
7 1
2 3
2 4
3 5

output:

5

result:

ok single line: '5'

Test #2:

score: 5.88235
Accepted
time: 0ms
memory: 16032kb

input:

500 500
93 218
275 474
211 161
103 350
243 150
410 311
250 68
93 360
427 274
89 424
253 149
215 59
248 64
111 114
111 289
234 184
328 321
332 253
397 496
75 82
483 255
445 497
130 284
219 177
138 268
408 273
412 184
111 204
216 124
471 497
352 401
241 383
147 214
381 179
356 492
443 253
130 287
417 ...

output:

9793

result:

ok single line: '9793'

Test #3:

score: 5.88235
Accepted
time: 34ms
memory: 25932kb

input:

500 124750
59 319
110 382
338 175
138 356
25 420
352 51
265 286
488 240
218 374
224 207
204 358
80 354
259 171
136 400
343 155
235 103
433 342
424 101
238 96
280 20
125 142
460 134
485 439
192 227
445 150
161 328
410 153
73 255
131 470
389 303
339 405
433 11
106 248
435 488
292 320
114 153
166 173
1...

output:

0

result:

ok single line: '0'

Test #4:

score: 5.88235
Accepted
time: 67ms
memory: 30800kb

input:

5000 200000
4836 4504
4279 4864
3489 2988
1123 4882
4516 1265
26 3897
1808 4315
1959 820
45 3063
3220 221
2181 96
3932 4726
866 2207
880 3004
4218 3667
4352 2640
2609 1305
792 1144
2623 904
2008 1206
1985 3164
694 3838
1878 1759
3434 1794
2774 1265
4478 4648
3188 4055
379 2489
4592 4736
4382 4151
17...

output:

11670941

result:

ok single line: '11670941'

Test #5:

score: 5.88235
Accepted
time: 78ms
memory: 31144kb

input:

10000 200000
552 2220
3638 2068
4885 899
7660 3542
9909 2969
6495 808
2426 4414
8800 1110
1191 4143
6288 5237
6000 7319
934 2847
8335 3276
9581 1657
906 9603
4775 244
8434 6999
230 5632
6910 17
6398 9257
7206 2591
1998 8705
5755 23
9815 646
3416 8138
7709 1955
292 9347
1115 4744
9650 2754
8167 9431
...

output:

44970718

result:

ok single line: '44970718'

Test #6:

score: 5.88235
Accepted
time: 92ms
memory: 29984kb

input:

10000 200000
23 9475
21 643
3 9851
6085 14
4829 9
11 7551
13 2399
7244 17
4731 21
22 8018
2 6739
3571 21
4426 18
4 849
2179 11
4603 18
7877 7
7201 15
8819 24
3060 7
19 3883
11 7101
9273 12
2439 18
596 10
4912 20
1517 5
9 6139
3958 5
5559 22
4624 23
21 8837
16 4162
9463 11
5519 21
4 4640
2 4076
24 9
...

output:

49792519

result:

ok single line: '49792519'

Test #7:

score: 5.88235
Accepted
time: 70ms
memory: 31072kb

input:

10000 200000
764 2274
4385 9783
9780 3081
5012 868
160 2685
6793 8689
3930 3810
6724 2882
3460 2134
2626 9313
2549 6006
1741 2304
9092 9377
5235 3847
6691 1934
4827 2049
3724 9513
3659 2766
7687 9580
5727 1428
4529 5473
2828 6575
4591 4334
9863 4130
1805 3434
5040 4224
6344 6570
4052 4149
4396 923
6...

output:

44849714

result:

ok single line: '44849714'

Test #8:

score: 5.88235
Accepted
time: 146ms
memory: 41268kb

input:

200000 200000
174693 2223
75507 173846
84474 46548
86098 153219
174425 104540
29307 111076
80539 152186
123942 4257
96429 57818
66758 10763
58431 13163
25573 60126
88050 14190
189049 78731
69096 134720
5747 66531
114074 76195
187769 56419
22763 86499
160218 12752
13739 129760
159122 137394
91094 181...

output:

1042760514

result:

ok single line: '1042760514'

Test #9:

score: 5.88235
Accepted
time: 154ms
memory: 40936kb

input:

200000 200000
2075 72896
99159 1509
2665 28424
83705 27507
16813 79181
33357 63145
146938 190201
139827 140316
27203 179609
110616 109572
125916 77299
127919 164981
75045 188113
196680 20893
104222 13535
41895 129914
196130 194177
116355 48626
9341 181263
69384 14903
86982 122113
28033 95599
195752 ...

output:

1047015143

result:

ok single line: '1047015143'

Test #10:

score: 5.88235
Accepted
time: 146ms
memory: 40964kb

input:

200000 200000
154271 59755
88607 126735
99706 116669
39615 141848
33824 52723
136770 137078
67217 790
162531 39626
175530 144357
183562 108181
82737 108514
74672 116785
88371 165223
123559 56718
11290 130085
2358 161051
66380 181737
18093 67103
15372 22798
9380 88001
109522 146353
153382 39792
61959...

output:

1037032039

result:

ok single line: '1037032039'

Test #11:

score: 5.88235
Accepted
time: 145ms
memory: 40892kb

input:

200000 200000
13662 36056
38825 92648
84044 21036
179276 2557
18564 188369
142758 145999
157084 178788
147373 33019
194022 4097
63276 155627
151802 184263
68928 37943
22334 172808
142551 154973
11136 156668
80339 124262
143576 179540
110482 101290
197343 135787
47977 85434
12738 8602
14006 95295
120...

output:

1057227267

result:

ok single line: '1057227267'

Test #12:

score: 5.88235
Accepted
time: 128ms
memory: 37676kb

input:

200000 199999
89248 100000
17288 100000
100000 70099
100000 59090
100000 145197
135205 100000
96310 100000
100000 37977
181461 100000
100000 191554
112633 100000
100000 188643
100000 140594
40534 100000
100000 28861
32875 100000
100000 7487
100000 197320
24322 100000
84349 100000
157892 100000
10000...

output:

4999950000

result:

ok single line: '4999950000'

Test #13:

score: 5.88235
Accepted
time: 72ms
memory: 36184kb

input:

200000 200000
121473 200000
200000 178604
151723 200000
121474 200000
200000 77612
132388 199999
199999 144012
199999 99405
106120 199999
199999 122896
144580 200000
199999 107682
124892 199999
200000 57756
157541 199999
39368 200000
200000 108621
102320 199999
199999 23673
200000 167337
123628 1999...

output:

0

result:

ok single line: '0'

Test #14:

score: 5.88235
Accepted
time: 128ms
memory: 37136kb

input:

200000 200000
184386 100000
100000 73260
99999 40259
100000 63888
107807 100000
100000 106995
100000 193273
100000 43794
69069 100000
45319 100000
100000 22364
159902 99999
100000 106867
100000 23526
99999 143699
100000 196570
2314 100000
100000 176702
139357 99999
196690 99999
37969 99999
99999 725...

output:

2809638269

result:

ok single line: '2809638269'

Test #15:

score: 5.88235
Accepted
time: 157ms
memory: 47760kb

input:

200000 200000
162723 4245
22199 272
1378 185336
164467 1530
42424 559
6500 4589
110181 3589
84482 4036
141189 837
198 23321
4993 164693
17481 3803
2549 54737
548 95535
74070 708
70106 1495
164224 3329
117761 3116
2100 138961
26741 1953
132814 399
392 117787
96710 146
664 156505
3198 29663
4874 68003...

output:

7599654801

result:

ok single line: '7599654801'

Test #16:

score: 5.88235
Accepted
time: 161ms
memory: 38384kb

input:

200000 200000
1 65334
2 61726
1 140899
130770 2
168914 1
34206 2
112792 2
70414 1
2 72310
61633 1
1 79011
2 54929
1 164253
39905 2
176563 2
1 90542
19295 1
165614 1
197077 2
1 23540
49001 2
1 157881
1 156372
57520 1
2 115212
1 152091
127516 2
78326 2
124358 1
199871 2
153131 1
1 164786
2 141681
1189...

output:

11212156878

result:

ok single line: '11212156878'

Test #17:

score: 5.88235
Accepted
time: 175ms
memory: 37532kb

input:

200000 200000
1 186687
1 12389
1 121975
168623 1
1 151266
69659 1
1 157700
1 144532
1 147765
1 191141
27509 1
157782 1
1 175077
1 182609
1 83843
1 5781
1 73038
1 81489
66675 1
15077 1
1 184982
195047 1
1 44949
1 153871
1 75510
1 139020
1 105740
1 171350
1 182523
100886 1
44907 1
1 133941
125600 1
1 ...

output:

19999700000

result:

ok single line: '19999700000'