QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511055#3403. Crossing RiversPetroTarnavskyi#WA 0ms3560kbC++202.6kb2024-08-09 15:43:272024-08-09 15:43:28

Judging History

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

  • [2024-08-09 15:43:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-08-09 15:43:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int n, Q;

struct DSU
{
	int n;
	VI p, sz;
	VI xr, val;
	
	void init(int _n)
	{
		n = _n;
		p.resize(n);
		iota(ALL(p), 0);
		sz.assign(n, 1);
		xr.assign(n, 0);
		val.assign(n, -1);
	}
	PII find(int v)
	{
		if (v == p[v])
			return {v, xr[v]};
		PII res = find(p[v]);
		return {res.F, res.S ^ xr[v]};
	}
	bool unite(int u, int v, int x)
	{
		PII U = find(u);
		PII V = find(v);
		u = U.F;
		v = V.F;
		if (u == v)
			return (U.S ^ V.S) == x;
		if (sz[u] > sz[v])
			swap(u, v);
		p[u] = v;
		xr[u] = x ^ U.S ^ U.F;
		sz[v] += sz[u];
		if (val[u] != -1 && val[v] != -1 && (val[u] ^ xr[u]) != val[v])
			return false;
		if (val[u] != -1 && val[v] == 1)
			val[v] = val[u] ^ xr[u];
		return true;
	}
};

void solve()
{
	DSU d;
	d.init(n);
	int cnt = 0;
	string s;
	getline(cin, s);
	bool ok = true;
	FOR (i, 0, Q)
	{
		getline(cin, s);
		if (!ok)
			continue;
		stringstream ss(s);
		char c;
		ss >> c;
		int x;
		VI v;
		while (ss >> x)
			v.PB(x);
		if (c == 'I')
		{
			cnt++;
			if (SZ(v) == 2)
			{
				int p = v[0];
				int val = v[1];
				auto res = d.find(p);
				if (d.val[res.F] == -1)
					d.val[res.F] = val;
				if (d.val[res.F] != val)
				{
					cout << "The first " << cnt << " facts are conflicting.\n";
					ok = false;
				}
			}
			else
			{
				assert(SZ(v) == 3);
				int p = v[0];
				int q = v[1];
				int val = v[2];
				ok &= d.unite(p, q, val);
				if (!ok)
				{
					cout << "The first " << cnt << " facts are conflicting.\n";					
				}
			}
		}
		else
		{
			assert(c == 'Q');
			int xr = 0;
			map<int, int> mp;
			FOR (j, 0, v[0])
			{
				int p = v[j + 1];
				PII res = d.find(p);
				mp[res.F]++;
				xr ^= res.S;
			}
			bool know = true;
			for (auto [p, ch] : mp)
			{
				if (ch & 1)
				{
					if (d.val[p] == -1)
						know = false;
					else
						xr ^= d.val[p];
				}
			}
			if (!know)
				cout << "I don't know.\n";
			else
				cout << xr << '\n';
			
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for (int tc = 1; ; tc++)
	{
		cin >> n >> Q;
		if (n == 0)
			break;
		cout << "Case " << tc << ":\n";
		solve();
		cout << '\n';
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3560kb

input:

0 811
8 860
37 20 15
73 29 22
124 42 2
169 86 25
289 18 9
325 176 28
551 68 13
717 24 16
4 573
203 64 8
272 35 19
386 37 30
457 115 18
6 609
70 37 30
110 96 16
229 79 9
329 126 16
468 76 26
575 27 23
2 717
172 89 19
690 15 17
9 993
0 40 11
71 1 22
144 7 17
198 45 9
260 46 27
324 139 12
652 25 16
765...

output:


result:

wrong answer 1st lines differ - expected: 'Case 1: 811.000', found: ''