QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257969 | #1957. Friendship Graphs | AliVu | WA | 57ms | 12248kb | C++14 | 1.7kb | 2023-11-19 14:04:27 | 2023-11-19 14:04:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define el '\n'
const int maxn = 1e3 + 3;
vector<int> e[maxn];
int used[maxn];
bool cmp(const int &u, const int &v) {
return e[u].size() < e[v].size();
}
void Solve() {
int n, m; cin >> n >> m;
for(int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
for(int i = 1; i <= n; i++) sort(e[i].begin(), e[i].end(), cmp);
// for(int i = 1; i <= n; i++) {
// cout << i << ": ";
// for(int v : e[i]) cout << v << ' ';
// cout << el;
// }
int id = -1;
for(int i = 1; i <= n; i++) if(id == -1 | e[id].size() > e[i].size()) id = i;
used[id] = 1;
int sz1 = 1;
for(int v : e[id]) {
int ok = 0;
for(int u : e[v]) ok += used[u];
if(ok == sz1) {
used[v] = 1;
++sz1;
}
}
bool dt2 = 0;
int sz2 = 0;
// cout << sz1 << el;
for(int i = 1; i <= n; i++) if(!used[i]) {
if (dt2){
cout << -1;
return;
}
used[i] = 2;
sz2 = 1;
for(int v : e[i]) {
if(used[v]) continue;
int ok = 0;
for(int u : e[v]) ok += (used[u] == 2);
if(ok == sz2) {
++sz2;
used[v] = 2;
}
}
dt2 = true;
}
if(sz2 == 0) cout << sz1 % 2;
else cout << abs(sz1 - sz2);
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);freopen("out.txt", "w", stdout);
// #endif
int t = 1;// cin >> t;
while(t--) Solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 49ms
memory: 12248kb
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: 53ms
memory: 12220kb
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: 47ms
memory: 12232kb
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: -100
Wrong Answer
time: 57ms
memory: 12248kb
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:
998
result:
wrong answer 1st lines differ - expected: '0', found: '998'