QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#635479#9420. Find Yourselfwoodie_0064#WA 0ms3620kbC++201.7kb2024-10-12 19:56:062024-10-12 19:56:07

Judging History

This is the latest submission verdict.

  • [2024-10-12 19:56:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3620kb
  • [2024-10-12 19:56:06]
  • Submitted

answer

#include <bits/stdc++.h>
#define bit(x) (1LL << (x))
using namespace std;
const int N = 1e5 + 3;
int T;
int n, num, m, x, y;


void work(){
	cin >> n >> m;
	vector<vector<pair <int,int>>> g(n);
	vector <pair <int,int>> e;
	for(int i = 0; i < m; ++i){
		cin >> x >> y;
		x -= 1;y -= 1;
		g[x].push_back({y,i});
		g[y].push_back({x,i});
		e.push_back({x,y});
	}
	vector <array <int,20>> prt(n);
	vector <int> dep(n),vis(m),dfn(n);
	auto dfs = [&] (auto &&self,int u,int fa) -> void{
		for(auto [v,w] : g[u]) if(!dfn[v]) {
			prt[v][0] = u;
			vis[w] = 1;
			dfn[v] = 1;
			dep[v] = dep[u] + 1;
			for(int i = 1;i < 20;i++) prt[v][i] = prt[prt[v][i - 1]][i - 1];
			self(self,v,u);
		}
	};
	dfn[0] = 1;
	dfs(dfs,0,-1);
	auto LCA = [&] (int u,int v) {
		if(dep[u] < dep[v]) swap(u,v);
		int d = dep[u] - dep[v];
		for(int i = 19;i >= 0;i--) if(bit(i) & d) {
			u = prt[u][i];
		}
		if(u == v) return u;
		for(int i = 19;i>= 0;i--) if(prt[u][i] != prt[v][i]) {
			u = prt[u][i];
			v = prt[v][i];
		}
		return prt[u][0];
	};
	
	vector <int> col(n);
	
	auto color = [&] (int u,int lca) {
		while(u != lca) {
			if(col[u]) return false;
			col[u] = 1;
			u = prt[u][0];
		}	
		return true;
	};
	
	for(int i = 0;i < m;i++) if(!vis[i]) {
		auto [u,v] = e[i];
		int lca = LCA(u,v);
		if(dep[u] + dep[v] - dep[lca] * 2 == 3) {
			if((!color(u,lca)) || (!color(v,lca))) {
				cout << "NO\n";
				return;
			}
		}else {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}


int main(){
//	freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> T;
	while(T--){
		work();
	}	
	return 0;
}

詳細信息

Test #1:

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

input:

3
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1

output:

NO
YES
NO

result:

ok 3 token(s): yes count is 1, no count is 2

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

10
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
4 8
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
7 8
1 3
1 4
1 5
2 3
2 4
2 5
3 6
4 7
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 10
1 3
1 4
1 5
2 3
2 4
2 5
1 6
2 7
3 8
...

output:

YES
YES
YES
NO
YES
YES
NO
NO
YES
YES

result:

wrong answer expected NO, found YES [1st token]