QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#270280 | #7755. Game on a Forest | ucup-team859# | WA | 2ms | 5868kb | C++17 | 1.3kb | 2023-11-30 17:55:44 | 2023-11-30 17:55:45 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxN = 100005;
vector <int> G[maxN];
bool used[maxN];
int dfs(int nod) {
used[nod] = 1;
int sz = 1;
for (int vecin : G[nod]) {
if (!used[vecin]) {
sz += dfs(vecin);
}
}
return sz;
}
void solve() {
int n, m, ans = 0;
cin >> n >> m;
int nr = n - m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
if (used[i]) {
continue;
}
int sz = dfs(i);
if (nr % 2 == 1) {
if (sz % 2 == 0) {
ans += sz - 1;
}
else {
ans += sz;
}
}
else {
if (sz % 2 == 1) {
ans += sz - 1;
}
else {
ans += sz;
}
}
}
cout << ans;
}
int main() {
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif // LOCAL
int nrTeste = 1;
//cin >> nrTeste;
while (nrTeste--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5868kb
input:
3 1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
4 3 1 2 2 3 3 4
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 5784kb
input:
100000 1 4647 17816
output:
99999
result:
wrong answer 1st numbers differ - expected: '1', found: '99999'