QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#622777#5307. Subgraph Isomorphismarthur_9548WA 54ms3808kbC++201.2kb2024-10-09 05:24:482024-10-09 05:24:49

Judging History

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

  • [2024-10-09 05:24:49]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:3808kb
  • [2024-10-09 05:24:48]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(int)(a); i < (int)(b);i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl
#define esp ' '
#define pii pair<int,int>
#define vi vector<int>
#define sz(x) ((int)(x).size())

using namespace std;

constexpr int oo = 0x3f3f3f3f3f3f3f3f;
constexpr int M = 23785125;
constexpr int mxI = 60;

struct DSU {
	vi p, rnk;
	DSU(int n) : p(n), rnk(n,0) {
		iota(all(p),0);
	}

	int find(int x) {
		return p[x] == x ? x : p[x]=find(p[x]);
	}

	bool merge(int a, int b) {
		a=find(a);
		b=find(b);
		if (a == b) return false;
		if (rnk[a] > rnk[b]) swap(a,b);

		rnk[b] += rnk[a]==rnk[b];
		p[a]=b;
		return true;
	}
};

void solve() {
	int n,m;cin>>n>>m;
	vector<vi> g(n);
	rep(i,0,m) {
		int a,b;cin>>a>>b;a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	if (m == n-1) {
		cout << "YES\n";
		return;
	}
	if (m > n) {
		cout << "NO\n";
		return;
	}

	rep(a,0,n) {
		if (sz(g[a]) != 2) {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}

signed main() {
	ios_base::sync_with_stdio(0);cin.tie(0);

	int t=1;
	cin>>t;
	while(t--) solve();
}

詳細信息

Test #1:

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

input:

4
7 6
1 2
2 3
3 4
4 5
5 6
3 7
3 3
1 2
2 3
3 1
5 5
1 2
2 3
3 4
4 1
1 5
1 0

output:

YES
YES
NO
YES

result:

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

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 3624kb

input:

33192
2 1
1 2
3 2
1 3
2 3
3 3
1 2
1 3
2 3
4 3
1 4
2 4
3 4
4 3
1 3
1 4
2 4
4 4
1 3
1 4
2 4
3 4
4 4
1 3
1 4
2 3
2 4
4 5
1 3
1 4
2 3
2 4
3 4
4 6
1 2
1 3
1 4
2 3
2 4
3 4
5 4
1 5
2 5
3 5
4 5
5 4
1 4
1 5
2 5
3 5
5 5
1 4
1 5
2 5
3 5
4 5
5 5
1 4
1 5
2 4
3 5
4 5
5 5
1 4
1 5
2 4
2 5
3 5
5 6
1 4
1 5
2 4
2 5
3 ...

output:

YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

wrong answer expected YES, found NO [39th token]