QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#340603#7313. Connected Spanning SubgraphSKHUOWA 259ms10316kbC++14780b2024-02-29 10:38:572024-02-29 10:38:58

Judging History

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

  • [2024-02-29 10:38:58]
  • 评测
  • 测评结果:WA
  • 用时:259ms
  • 内存:10316kb
  • [2024-02-29 10:38:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int n, m;
int col[N];
vector<int> e[N];

bool dfs(int u, int c) {
  col[u] = c;
  bool res = 1;
  for (auto v : e[u]) {
    if (col[v] == !c) continue;
    if (col[v] == c) return 0;
    res &= dfs(v, !c);
    if (!res) return 0;
  }
  return 1;
}

void solve() {
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    e[u].emplace_back(v), e[v].emplace_back(u);
  }
  
  memset(col, -1, sizeof(col));
  if (!dfs(1, 0)) {
    cout << "0\n";
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (col[i] == -1) {
      cout << "0\n";
      return;
    }
  }
  cout << "1\n";
}

int main() {
  
  while (cin >> n >> m) solve();
  
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9132kb

input:

2 1
1 2
3 2
1 2
2 3
3 3
1 2
2 3
3 1

output:

1
1
0

result:

ok 3 number(s): "1 1 0"

Test #2:

score: -100
Wrong Answer
time: 259ms
memory: 10316kb

input:

11 14
7 5
2 6
10 3
8 2
8 11
4 6
11 1
5 6
1 10
5 4
5 2
4 3
1 7
8 9
4 4
1 4
2 4
2 3
3 4
10 18
9 10
1 8
10 6
3 5
4 10
10 8
3 1
2 6
4 2
8 2
3 2
5 9
6 5
5 4
8 7
9 7
10 3
1 4
3 2
3 1
2 1
15 27
10 2
3 12
12 6
8 4
5 8
6 9
9 7
4 9
1 6
3 14
13 8
2 12
2 6
8 11
4 11
14 1
15 5
13 11
1 12
15 2
11 15
12 11
15 14
8...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 3rd numbers differ - expected: '1', found: '0'