QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574355#9319. Bull FarmMaxDYFWA 23ms3836kbC++233.9kb2024-09-18 21:43:202024-09-18 21:43:20

Judging History

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

  • [2024-09-18 21:43:20]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3836kb
  • [2024-09-18 21:43:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct DSU
{
	vector<int> f;
	DSU(int n)
	{
		f.resize(n + 1);
		for (int i = 0; i <= n; i++)
			f[i] = i;
	}
	int find(int x)
	{
		return f[x] != x ? f[x] = find(f[x]) : x;
	}
	void merge(int x, int y)
	{
		if (find(x) != find(y))
			f[find(x)] = y;
	}
};
struct Graph
{
	vector<vector<pair<int, int>>> G;
	int n;
	struct Subgraph
	{
		vector<int> dis;
		vector<vector<pair<int, int>>> &G;
		int n;
		Subgraph(int n, vector<vector<pair<int, int>>> &G) : n(n), G(G)
		{
			dis = vector<int>(n + 1, inf);
		}
		void getPath(int x)
		{
			dis[x] = 0;
			vector<int> vis(n + 1);
			priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
			for (int i = 1; i <= n; i++)
				if (dis[i] != inf)
					q.push({dis[i], i});
			while (q.empty() == false)
			{
				auto [d, x] = q.top();
				q.pop();
				if (vis[x])
					continue;
				vis[x] = 1;
				for (auto [y, c] : G[x])
				{
					if (dis[y] > max(dis[x], c))
					{
						dis[y] = max(dis[x], c);
						q.push({dis[y], y});
					}
				}
			}
		}
	};
	vector<Subgraph> g;
	Graph(int n) : n(n)
	{
		G = vector<vector<pair<int, int>>>(n + 1);
		g = vector<Subgraph>(n + 1, Subgraph(n, G));
	}
	void add(int x, int y, int c)
	{
		if (x == y)
			return;
		G[x].push_back({y, c});
	}
	void getPath()
	{
		for (int i = 1; i <= n; i++)
			g[i].getPath(i);
	}
	void link(int x, int y, int c)
	{
		g[x].dis[y] = min(g[x].dis[y], c);
		g[y].dis[x] = min(g[y].dis[x], c);
	}
	int query(int x, int y)
	{
		return g[x].dis[y];
	}
};
void work()
{
	int n, l, q;
	cin >> n >> l >> q;
	DSU dsu(n);
	Graph g(n);
	auto decode = [&](char ch1, char ch2)
	{
		int x = (int)(ch1 - '0') * 50 + (int)(ch2 - '0');
		return x;
	};
	for (int c = 1; c <= l; c++)
	{
		vector<int> t(n + 1), in(n + 1);
		for (int j = 1; j <= n; j++)
		{
			char ch1, ch2;
			cin >> ch1 >> ch2;
			t[j] = decode(ch1, ch2);
			in[t[j]]++;
		}
		int in1 = 0, in2 = 0, in2x = 0, in0x = 0;
		bool flag = 1;
		for (int i = 1; i <= n; i++)
		{
			if (in[i] > 2)
			{
				flag = 0;
				break;
			}
			if (in[i] == 1)
				in1++;
			else if (in[i] == 2)
				in2++, in2x = i;
			else if (in[i] == 0)
				in0x = i;
		}
		if (flag == 0)
			continue;
		if (in1 == n)
		{
			vector<int> vis(n + 1);
			for (int i = 1; i <= n; i++)
			{
				int x = i, lst = 0;
				if (!vis[x])
				{
					vector<int> proc;
					while (!vis[x])
					{
						vis[x] = 1;
						if (lst == 0 || dsu.find(lst) != dsu.find(x))
						{
							proc.push_back(x);
							if (lst)
								dsu.merge(lst, x);
						}
						lst = x;
						x = t[x];
					}
					for (int i = 0; i < proc.size(); i++)
						for (int j = i + 1; j < proc.size(); j++)
							g.link(proc[i], proc[j], c);
				}
			}
		}
		else if (in1 == n - 2 && in2 == 1)
		{
			vector<int> vis(n + 1);
			for (int i = 1; i <= n; i++)
				if (t[i] == in2x)
					g.add(i, in0x, c);
			int x = in0x;
			while (!vis[x])
			{
				vis[x] = 1;
				x = t[x];
			}
			for (int i = 1; i <= n; i++)
			{
				int x = i, lst = 0;
				if (!vis[x])
				{
					vector<int> proc;
					while (!vis[x])
					{
						vis[x] = 1;
						if (lst == 0 || dsu.find(lst) != dsu.find(x))
						{
							proc.push_back(x);
							if (lst)
								dsu.merge(lst, x);
						}
						lst = x;
						x = t[x];
					}
					for (int i = 0; i < proc.size(); i++)
						for (int j = i + 1; j < proc.size(); j++)
							g.link(proc[i], proc[j], c);
				}
			}
		}
		else
			continue;
	}
	g.getPath();
	for (int i = 1; i <= q; i++)
	{
		char ch[7];
		cin >> ch;
		int a = decode(ch[0], ch[1]), b = decode(ch[2], ch[3]), c = decode(ch[4], ch[5]);
		cout << (g.query(a, b) <= c ? '1' : '0');
	}
	cout << '\n';
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
		work();
}

详细

Test #1:

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

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Wrong Answer
time: 23ms
memory: 3644kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

010000001101101111101010001101100000001111110101001110100100001011010101110111000011000100110111110100001001100011110101110101111011001010100100011110010111000000000111111010011111101001111010101010001111010111001111111100111010100111001001010100000110011011100000100100100110001010100001011101101110...

result:

wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '010000001101101111101010001101...1111111111111101001111011011101'