Submission #43895924


Source Code Expand

// LUOGU_RID: 117034367
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
const int N = 1e5 + 10;
int n, d, x[N], y[N];
vector <int> v[N];
struct edge {
    int to, flow;
    unsigned pos;
};
vector <edge> a[N];
void add(int x, int y, int flow) {
    a[x].push_back((edge) { y, flow, (unsigned) a[y].size() });
    a[y].push_back((edge) { x, 0, (unsigned) a[x].size() - 1 });
}
int dep[N];
unsigned cur[N];
queue <int> q;
bool bfs(int s, int t) {
    F(i, s, t) dep[i] = 0;
    dep[s] = 1;
    q.push(s);
    while (q.size()) {
        int x = q.front(); q.pop();
        for (edge i: a[x])
            if (i.flow && !dep[i.to]) {
                dep[i.to] = dep[x] + 1;
                q.push(i.to);
            }
    }
    return dep[t];
}
int dfs(int x, int tt, int lim) {
    if (x == tt) return lim;
    int ans = 0, t;
    for (unsigned &i = cur[x]; i < a[x].size(); ++i)
        if (a[x][i].flow && dep[a[x][i].to] == dep[x] + 1 && (t = dfs(a[x][i].to, tt, min(lim, a[x][i].flow)))) {
            a[x][i].flow -= t, a[a[x][i].to][a[x][i].pos].flow += t;
            lim -= t, ans += t;
            if (!lim) return ans;
        }
    return ans;
}
int dinic(int s, int t) {
    int ans = 0;
    while (bfs(s, t)) {
        F(i, s, t) cur[i] = 0;
        ans += dfs(s, t, 1e9);
    } return ans;
}
void zhk() {
	read(n), read(d);
	int s = 0, t = n * d + n + 1;
	F(i, s, t) a[i].clear();
	F(i, 1, n * d) {
		read(x[i]), read(y[i]);
		add(s, i, 1);
		add(i, n * d + x[i], 1e9);
		add(i, n * d + y[i], 1e9);
	}
	F(i, 1, n) add(n * d + i, t, d);
	if (dinic(s, t) < n * d) puts("No");
	else {
		add(s, 1, 1e9);
		dinic(s, t);
		F(i, 1, n * d)
			if (!dep[i]) {
				puts("No");
				return;
			}
		F(i, s, t) a[i].clear();
		F(i, 2, n * d) {
			add(i, t, 1);
			add(n * d + x[i], i, 1e9);
			add(n * d + y[i], i, 1e9);
		}
		F(i, 1, n) add(s, n * d + i, d);
		dinic(s, t);
		// F(i, 1, n) cout << dep[n * d + i] << " "; cout << endl;
		F(i, 1, n)
			if (!dep[n * d + i]) {
				puts("No");
				return;
			}
		puts("Yes");
	}
}
signed main() {
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}

Submission Info

Submission Time
Task F - Everywhere is Sparser than Whole (Judge)
User ast123
Language C++ (GCC 9.2.1)
Score 900
Code Size 2691 Byte
Status AC
Exec Time 1304 ms
Memory 18384 KiB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 900 / 900 0 / 0
Status
AC × 1
AC × 43
AC × 3
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt
after_contest after_contest_001.txt, after_contest_002.txt, after_contest_003.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 10 ms 8292 KiB
01-001.txt AC 34 ms 8244 KiB
01-002.txt AC 28 ms 8320 KiB
01-003.txt AC 35 ms 9216 KiB
01-004.txt AC 33 ms 9140 KiB
01-005.txt AC 38 ms 8648 KiB
01-006.txt AC 42 ms 9056 KiB
01-007.txt AC 44 ms 11976 KiB
01-008.txt AC 45 ms 12084 KiB
01-009.txt AC 44 ms 8748 KiB
01-010.txt AC 41 ms 9124 KiB
01-011.txt AC 42 ms 12484 KiB
01-012.txt AC 44 ms 12636 KiB
01-013.txt AC 43 ms 18216 KiB
01-014.txt AC 61 ms 17936 KiB
01-015.txt AC 93 ms 16484 KiB
01-016.txt AC 69 ms 16132 KiB
01-017.txt AC 28 ms 11784 KiB
01-018.txt AC 30 ms 11636 KiB
01-019.txt AC 24 ms 11392 KiB
01-020.txt AC 27 ms 11388 KiB
01-021.txt AC 28 ms 10692 KiB
01-022.txt AC 35 ms 15328 KiB
01-023.txt AC 33 ms 15036 KiB
01-024.txt AC 24 ms 10928 KiB
01-025.txt AC 22 ms 10960 KiB
01-026.txt AC 19 ms 9388 KiB
01-027.txt AC 19 ms 8672 KiB
01-028.txt AC 15 ms 8404 KiB
01-029.txt AC 21 ms 8164 KiB
01-030.txt AC 57 ms 18184 KiB
01-031.txt AC 45 ms 18152 KiB
01-032.txt AC 41 ms 16900 KiB
01-033.txt AC 205 ms 18000 KiB
01-034.txt AC 194 ms 17868 KiB
01-035.txt AC 126 ms 16024 KiB
01-036.txt AC 88 ms 16480 KiB
01-037.txt AC 92 ms 16644 KiB
01-038.txt AC 65 ms 15172 KiB
01-039.txt AC 45 ms 9448 KiB
01-040.txt AC 35 ms 8280 KiB
01-041.txt AC 1304 ms 18384 KiB
01-042.txt AC 59 ms 18160 KiB
after_contest_001.txt AC 30 ms 8964 KiB
after_contest_002.txt AC 59 ms 15876 KiB
after_contest_003.txt AC 57 ms 15856 KiB