QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#46707 | #1957. Friendship Graphs | meomeo | WA | 264ms | 4828kb | C++ | 1.9kb | 2022-08-31 00:25:05 | 2022-08-31 00:25:07 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>,
rb_tree_tag,tree_order_statistics_node_update>;
const int maxn = 1001;
bool color[maxn], c[maxn][maxn], vis[maxn], ok = 0;
int n;
int res;
void dfs(int u) {
vis[u] = 1;
if (color[u] == 0) {
res++;
}
else {
res--;
}
for (int i = 0 ; i < n ; i++) {
if (!c[u][i]) continue;
if (u == i) continue;
if (!vis[i]) {
color[i] = color[u] ^ 1;
dfs(i);
}
else {
if (color[i] == color[u]) {
ok = 1;
}
}
}
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int m;
cin >> n >> m;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < n ; j++) {
c[i][j] = 1;
}
}
for (int i = 0 ; i < m ; i++) {
int u, v;
cin >> u >> v;
c[u-1][v-1] = c[v-1][u-1] = 0;
}
vector<pair<int, int>> bag;
for (int i = 0 ; i < n ; i++) {
if (!vis[i]) {
dfs(i);
bag.push_back({res, -res});
res = 0;
}
}
map<int, int> dp, pre;
pre[0] = 1;
for (auto &[u, v]: bag) {
for (int i = -1000 ; i <= 1000 ; i++) {
dp[i] |= pre[i - u];
dp[i] |= pre[i - v];
}
pre = dp;
dp.clear();
}
res = 1E18;
for (int i = -1000 ; i <= 1000 ; i++) {
if (dp[i]) {
res = min(res, abs(i));
}
}
if (!ok) {
cout << abs(res);
}
else {
cout << -1;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 264ms
memory: 4828kb
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:
1000000000000000000
result:
wrong answer 1st lines differ - expected: '0', found: '1000000000000000000'