QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#257953 | #1957. Friendship Graphs | superduchackgv | WA | 139ms | 7924kb | C++20 | 2.8kb | 2023-11-19 13:58:12 | 2023-11-19 13:58:12 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define vt vector
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
typedef unsigned long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vt<int> vti;
const double Pi = acos(- 1.0);
template<typename T>ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {for(T x : vec) cout << x << ' '; cout << endl;return os;}
const int inf = INT_MAX;
void Duck(){
int n, m; cin >> n >> m;
vt<vti> g(n);
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
--u;
--v;
g[u].pb(v);
g[v].pb(u);
}
vti pos(n);
iota(all(pos), 0);
sort(all(pos), [&](int i, int j){
return g[i].size() < g[j].size();
});
vti used(n);
for(int i = 0; i < n; i++){
sort(all(g[i]), [&](int u, int v){
return g[u].size() < g[v].size();
});
}
//for(int i = 0; i < n; i++){
// cout << pos[i] << ' ' << g[pos[i]];
//}
used[pos[0]] = 1;
vti a;
a.pb(pos[0]);
for(int v : g[pos[0]]){
bool ok = 1;
for(int i : a){
bool f = 0;
for(int j : g[v]){
if(i == j){
f = 1;
break;
}
}
if(!f){
ok = 0;
break;
}
}
if(ok) a.pb(v), used[v] = 1;
}
//cout << used;
//cout << a;
vti b;
for(int i = 0; i < n; i++){
if(!used[i]) b.pb(i);
}
bool ok = 1;
for(int v : b){
if(!ok) break;
for(int i : b){
if(i == v) continue;
bool f = 0;
for(int j : g[v]){
if(i == j){
f = 1;
}
}
if(!f) ok = 0;
}
}
if(ok){
if(a.size() < n / 2){
// if(b.size() - a.size() == 9){
// cout << 5;
// return;
// }
// cout << b.size() - a.size();
cout << (g[pos[0]].size());
}
else{
cout << (n & 1);
}
}
else{
cout << -1;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
/*Duck3*/
int t = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//cin >> t;
while(t--) Duck();
return 0;
}
/*
Test:
*/
詳細信息
Test #1:
score: 100
Accepted
time: 137ms
memory: 7924kb
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: -100
Wrong Answer
time: 139ms
memory: 7832kb
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:
996
result:
wrong answer 1st lines differ - expected: '2', found: '996'