QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718910#7898. I Just Want... One More...SmHaInTWA 108ms3748kbC++202.5kb2024-11-06 21:45:432024-11-06 21:45:43

Judging History

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

  • [2024-11-06 21:45:43]
  • 评测
  • 测评结果:WA
  • 用时:108ms
  • 内存:3748kb
  • [2024-11-06 21:45:43]
  • 提交

answer

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<string.h>
#include <string>
#include<math.h>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<queue>
#include<stack>
#include<functional>
#include<deque>
using namespace std;

const int MAXN = 201000;
#define int long long
#define ll long long
#define lll unsigned long long
#define PA pair<ll,ll>
#define INF (ll)0x3f3f3f3f*(ll)1000000
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = 1e9 + 7;



void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>>left(n + 1);
	for (int i = 1; i <= m; i++) {
		int x, y; cin >> x >> y;
		left[x].push_back(y);
	}

	bool visit[MAXN];
	vector<int>match(n + 1, 0);

	function<bool(int)>check = [&](int x)->bool {
		for (auto y : left[x]) {
			if (!visit[y]) {
				visit[y] = true;
				int t = match[y];
				if (!t || check(t)) {
					match[y] = x;
					return true;
				}
			}
		}
		return false;
	};

	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		memset(visit, 0, sizeof visit);
		if (check(i)) {
			cnt++;
		}
	}
	
	int s = 0, t = 2 * n + 1;
	vector<vector<int>>edge(2 * n + 2);

	vector<bool>canusel(n + 1, true);
	vector<bool>canuser(n + 1, true);
	for (int i = 1; i <= n; i++) {
		if (match[i]) {
			canusel[match[i]] = false;
			canuser[i] = false;
		}
	}

	for (int i = 1; i <= n; i++) {
		if (canusel[i]) {
			edge[i].push_back(s);
			edge[s].push_back(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (canuser[i]) {
			edge[i + n].push_back(t);
			edge[t].push_back(i + n);
		}
	}

	for (int i = 1; i <= n; i++) {
		for (auto y : left[i]) {
			edge[i].push_back(y + n);
			edge[y + n].push_back(i);
		}
	}

	vector<bool>visl(2 * n + 2, false);
	function<int(int, int)>dfsl = [&](int x, int fa)->int {
		int res = 0;
		
		visl[x] = true;
		if (x <= n && x > 0) {
			res++;
		}

		for (auto v : edge[x]) {
			if (v == fa || visl[v])continue;
			res += dfsl(v, x);
		}

		return res;
	};

	vector<bool>visr(2 * n + 2, false);
	function<int(int, int)>dfsr = [&](int x, int fa)->int {
		int res = 0;

		visr[x] = true;
		if (x > n && x <= 2*n) {
			res++;
		}

		for (auto v : edge[x]) {
			if (v == fa || visr[v])continue;
			res += dfsr(v, x);
		}

		return res;
	};

	int resl = dfsl(s, -1);
	int resr = dfsr(t, -1);

	cout << resl * resr << endl;
}

signed main() {
	IOS;
	int t = 1; cin >> t;
	while (t--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3732kb

input:

3
4 3
1 2
3 2
4 3
3 3
1 3
2 2
3 1
3 2
1 2
1 2

output:

6
0
4

result:

ok 3 number(s): "6 0 4"

Test #2:

score: -100
Wrong Answer
time: 108ms
memory: 3748kb

input:

10000
5 4
2 2
3 1
5 3
1 1
1 1
1 1
1 1
1 1
2 2
2 2
1 2
1 1
1 1
1 1
1 1
1 1
1 1
2 3
2 1
1 2
1 1
5 5
1 4
2 2
3 1
1 3
1 2
2 4
2 2
2 1
1 2
1 1
5 1
5 3
3 1
2 2
1 1
1 1
3 2
3 1
2 1
5 2
1 2
2 3
5 3
1 5
4 2
1 2
4 1
1 1
2 3
1 1
2 2
2 1
4 1
1 4
3 1
1 1
1 1
1 1
2 1
2 2
3 3
1 3
2 3
2 2
3 3
1 3
3 3
1 2
3 3
2 2
1 ...

output:

6
0
0
2
0
0
0
0
8
0
16
4
0
6
9
9
9
0
9
4
0
1
1
1
0
4
16
15
3
2
16
0
2
2
20
1
0
0
0
0
16
4
4
16
4
9
0
9
0
2
3
0
9
4
9
16
20
0
0
1
12
0
1
2
0
0
1
0
0
2
2
4
0
12
1
0
0
2
1
2
2
3
0
4
1
6
0
0
0
0
9
16
2
0
1
2
0
12
2
4
0
12
1
1
9
4
6
9
9
12
3
16
15
16
9
4
9
0
1
16
9
9
1
9
16
9
12
4
9
2
0
4
0
6
0
3
0
0
0
0...

result:

wrong answer 9th numbers differ - expected: '6', found: '8'