QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282706#7313. Connected Spanning SubgraphChrysanthBlossomWA 26ms11792kbC++14636b2023-12-12 20:06:412023-12-12 20:06:41

Judging History

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

  • [2023-12-12 20:06:41]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:11792kb
  • [2023-12-12 20:06:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n, m, col[300005];
vector<int> e[300005];
bool dfs(int k, int c){
	col[k] = c; int x = 3 - c;
	bool flag = true;
	for(int i = 0; i < e[k].size(); i++){
		if(!col[e[k][i]]) flag &= dfs(e[k][i], x);
		if(col[e[k][i]] != x) return false;
	}
	return flag;
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	while(cin >> n >> m){
		col[1] = 1;
		for(int i = 1, u, v; i <= m; i++) cin >> u >> v, e[u].push_back(v), e[v].push_back(u);
		if(dfs(1, 1)) cout << 1 << endl;
		else	   cout << 0 << endl;
		for(int i = 1; i <= n; i++) col[i] = 0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 26ms
memory: 11792kb

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'