QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527003#1957. Friendship Graphssroid_03#WA 441ms39908kbC++143.8kb2024-08-22 05:29:152024-08-22 05:29:15

Judging History

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

  • [2024-08-22 05:29:15]
  • 评测
  • 测评结果:WA
  • 用时:441ms
  • 内存:39908kb
  • [2024-08-22 05:29:15]
  • 提交

answer

// by Siddhid Saha (2112010)


#include <bits/stdc++.h>
#include <set>
using namespace std;

#define INF 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define PI atan(1)*4
#define set_bits __builtin_popcountllO
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define rvsort(a) sort(all(a),greater<int>())
#define read(a,n) for(int i = 0 ; i < n ; i ++){ cin >> a[i];}
#define printv(a) for(auto it: a){cout << it << " ";} cout << endl;
#define ms(arr, v) memset(arr, v, sizeof(arr))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
#include "/Users/templates/debug.h"
#else
#define dbg(x...)
#endif
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
void google(int t) {cout << "Case #" << t << ": ";}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll uid(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*--------------------------------------------------------------------------------------------------------------------------*/
//const int mod = 1e9 + 7;
//const int mod = 998244353; 


void solve()
{
    ll n, m; cin >> n >> m;
    set<pll> st;
    for(int i = 1 ; i <= n ; i ++){
        for(int j = i+1 ; j <= n ; j ++){
            st.insert({i, j});
        }
    }
    for(int i = 0 ; i < m ; i ++){
        ll u, v; cin >> u >> v;
        if(u > v) swap(u, v);
        st.erase({u, v});
    }
    vector<vll> adj(n+1);
    for(auto [x, y]: st){
        adj[x].pb(y);
        adj[y].pb(x);
    }
    vector<ll> vis(n+1, 0);
    bool ok = true;
    auto dfs = [&](auto &&dfs, ll node, ll c)->void{
        // dbg(node);
        vis[node] = c;
        for(auto it: adj[node]){
            if(vis[it] == 0){
                dfs(dfs, it, c == 1 ? 2 : 1);
            }else if(c == vis[it]){
                ok = false;
                return;
            }
        }
    };
    ll ct = 0;
    for(int i = 1; i <= n ; i ++){
        if(vis[i] == 0 && adj[i].size()){
            dfs(dfs, i, 1);
        }else if(adj[i].empty()){
            ct++;
        }
    }
    if(!ok){
        cout << -1 << endl;
        return;
    }
    ll cnt1 = count(all(vis), 1);
    ll cnt2 = count(all(vis), 2);
    ll ans = abs(cnt1-cnt2);
    if(ans >= ct){
        ans -= ct;
    }else{
        ct -= ans;
        ans = ct%2;
    }
    cout << ans << endl;

}

int main() {

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);


ll t = 1;
// cin >> t;
for(int i = 1 ; i <= t ; i++){
//google(i);
solve();
}
return 0;
}









详细

Test #1:

score: 100
Accepted
time: 407ms
memory: 34964kb

input:

1000 499000
20 615
260 390
779 37
13 563
650 605
358 684
783 370
162 90
379 662
88 208
458 371
178 3
590 762
455 514
738 641
270 805
205 881
205 315
837 54
976 579
519 532
982 669
563 804
648 274
268 293
182 392
337 772
961 603
294 607
546 772
189 218
702 266
515 610
691 965
643 235
509 193
184 302
...

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 378ms
memory: 34832kb

input:

1000 498999
35 65
880 835
501 309
590 758
882 857
356 493
43 623
644 637
361 785
58 317
26 11
595 521
723 629
611 36
789 29
30 650
426 475
852 862
667 137
677 173
656 44
457 279
680 567
789 989
368 873
510 721
128 584
835 956
419 779
607 568
317 790
932 580
336 400
74 265
772 855
939 816
448 883
381...

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 393ms
memory: 34964kb

input:

1000 498998
667 721
880 868
426 900
882 839
789 440
590 395
356 847
852 758
35 648
26 723
611 329
644 560
723 45
595 813
501 338
58 762
30 302
43 340
361 734
74 863
128 433
656 196
677 188
932 651
835 603
368 568
336 105
317 225
457 350
419 771
607 545
789 31
772 465
510 542
680 888
504 445
884 999
...

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 421ms
memory: 34604kb

input:

1000 499499
552 449
897 36
561 770
188 194
233 385
689 608
814 604
386 789
440 778
51 295
368 726
835 647
182 31
387 250
202 887
607 184
189 192
54 774
252 403
562 109
878 528
258 449
823 460
619 906
952 96
69 383
630 81
474 996
273 651
749 270
682 976
147 209
287 612
402 108
575 479
864 462
1000 72...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 415ms
memory: 34848kb

input:

1000 498751
681 409
733 39
732 717
449 73
41 314
80 971
61 44
139 989
93 338
235 188
113 955
362 380
471 183
228 566
120 625
543 1
450 262
411 197
470 342
461 616
704 186
345 782
499 672
391 288
541 531
917 742
736 819
345 428
821 265
321 789
270 742
452 609
386 668
60 440
421 23
386 677
167 69
944 ...

output:

498

result:

ok single line: '498'

Test #6:

score: 0
Accepted
time: 435ms
memory: 34780kb

input:

1000 499000
679 199
582 83
847 334
396 135
314 922
406 13
371 181
325 954
279 841
428 913
363 248
750 509
283 910
403 697
298 213
56 57
172 914
89 580
203 814
499 491
875 236
846 806
434 31
990 138
883 476
441 309
67 662
829 2
619 824
418 151
788 630
194 350
81 484
548 497
892 45
684 818
516 387
873...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 441ms
memory: 34904kb

input:

1000 498501
590 631
599 460
689 534
154 899
941 870
605 576
2 374
343 119
264 170
866 139
907 319
256 962
937 684
227 461
805 523
640 16
939 858
593 485
501 791
426 556
596 682
524 5
79 143
782 491
659 211
608 362
85 881
361 867
791 509
601 9
658 609
268 519
391 379
231 580
100 674
668 219
203 778
1...

output:

998

result:

ok single line: '998'

Test #8:

score: 0
Accepted
time: 325ms
memory: 38380kb

input:

1000 249500
596 90
14 715
205 280
125 829
988 726
888 600
689 300
576 837
407 955
473 827
181 232
871 719
528 529
981 53
348 17
245 859
135 52
98 955
671 45
735 48
612 327
122 141
697 215
527 884
31 16
408 262
826 153
464 675
526 344
744 739
838 337
860 9
988 526
498 101
324 212
752 129
119 191
660 ...

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 300ms
memory: 38616kb

input:

1000 249499
473 827
576 837
205 280
407 955
14 715
125 829
988 726
596 90
689 300
888 600
981 53
671 45
245 859
181 339
98 955
871 719
528 529
135 52
735 48
348 379
612 857
31 327
408 706
464 675
527 884
122 141
826 153
697 579
988 526
324 212
138 316
660 549
860 9
131 782
119 191
752 363
838 510
74...

output:

-1

result:

ok single line: '-1'

Test #10:

score: 0
Accepted
time: 310ms
memory: 39780kb

input:

1000 289101
851 683
314 539
40 366
43 66
782 468
282 843
284 650
455 144
416 146
694 563
879 73
619 563
229 447
472 349
659 262
792 343
690 177
565 191
844 716
756 24
728 971
911 540
675 85
934 110
496 726
956 615
713 747
252 960
77 707
247 671
53 417
334 414
713 24
269 547
399 864
160 542
761 133
3...

output:

398

result:

ok single line: '398'

Test #11:

score: 0
Accepted
time: 318ms
memory: 39908kb

input:

1000 289100
851 683
455 960
43 66
782 468
416 146
314 539
40 366
282 843
694 563
284 650
619 563
229 447
472 349
792 343
879 73
659 262
690 177
565 191
675 242
756 24
911 540
956 615
934 617
844 716
496 726
728 971
77 707
713 24
334 414
247 671
53 417
252 960
713 747
269 547
390 373
399 864
761 354
...

output:

-1

result:

ok single line: '-1'

Test #12:

score: 0
Accepted
time: 380ms
memory: 35444kb

input:

1000 409500
606 839
517 698
761 152
582 382
302 633
725 114
261 469
104 723
34 275
336 658
786 133
243 313
367 839
422 137
440 620
597 337
581 141
84 326
791 744
122 64
56 457
784 786
199 919
235 697
41 64
235 470
439 444
858 746
830 314
998 147
367 421
201 209
326 124
831 712
625 745
453 870
414 38...

output:

800

result:

ok single line: '800'

Test #13:

score: 0
Accepted
time: 386ms
memory: 35428kb

input:

1000 409499
761 661
302 728
517 190
582 357
725 64
606 591
261 659
104 158
581 526
367 591
440 221
56 668
336 313
243 409
786 151
791 356
422 775
84 679
597 859
122 109
34 261
784 170
235 927
199 217
998 923
830 900
858 646
41 109
235 719
439 872
625 322
414 963
929 562
33 373
435 392
531 676
831 88...

output:

-1

result:

ok single line: '-1'

Test #14:

score: -100
Wrong Answer
time: 0ms
memory: 3684kb

input:

17 121
2 5
16 5
3 14
15 16
16 6
10 16
9 5
17 7
12 5
9 16
2 7
3 10
3 1
4 7
15 1
15 8
9 17
4 8
4 13
11 6
9 7
15 17
12 9
10 7
11 13
2 8
17 6
14 17
9 13
1 9
10 6
16 13
9 6
10 13
15 13
8 5
17 5
14 1
3 2
2 13
12 1
2 9
15 6
9 11
2 10
3 8
10 8
15 9
14 11
4 11
2 4
12 8
12 17
3 16
12 14
2 14
10 5
8 7
15 5
10 ...

output:

9

result:

wrong answer 1st lines differ - expected: '5', found: '9'