Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> #pragma optimize("unroll-loops,no-stack-protector") using namespace std; namespace io { struct eof { eof() {} }; const int L = (1 << 21) | 5; char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55]; int f, qr; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; } inline void putc(char x) { *oS++ = x; if (oS == oT) flush(); } template <class I> inline void gi(I &x) { for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); (c < '0' || c > '9') && (c != EOF); c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) if (c == '-') f = -1; if (c == EOF) throw eof(); for (x = 0; c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) x = x * 10 + (c & 15); x *= f; } template <class I> inline void print(I x) { if (!x) putc('0'); if (x < 0) putc('-'), x = -x; while (x) qu[++qr] = x % 10 + '0', x /= 10; while (qr) putc(qu[qr--]); } inline void ps(const char *s) { int l = strlen(s), x; for (x = 0; x < l; x++) putc(s[x]); } struct IOC { ~IOC() { flush(); } } ioc; inline double readld() { double x = 0, y = 1; for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c < '0' || c > '9'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) if (c == '-') y = -1; assert(c != '.'); for (; c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) x = x * 10 + (c & 15); x *= y; assert(c != 'e'); if (c == '.') for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) y *= 0.1, x += y * (c & 15); return x; } inline void printld(double x, int y) { if (x < 0) putc('-'), x = -x; x += .5 * pow(.1, y); print((unsigned long long)x), putc('.'); for (x -= (unsigned long long)x; y; --y) x *= 10, putc((int)x + '0'), x -= (int)x; } } // namespace io using io::gi; using io::print; using io::putc; template <class T> int ctz(T a) { return sizeof(T) > 4 ? __builtin_ctzll(a) : __builtin_ctz(a); } template <class T> inline T gcd(T a, T b) { int shift = ctz(a | b); for (b >>= ctz(b), a >>= ctz(a); a; a -= b, a >>= ctz(a)) if (a < b) swap(a, b); return b << shift; } template <class T> void exgcd(T a, T b, T &x, T &y) { if (!b) return (void)(x = 1, y = 0); exgcd(b, a % b, y, x), y -= a / b * x; } template <class T> T Inv(T a, T p) { T x, y; exgcd(a, p, x, y); return (x % p + p) % p; } inline int fpow(int a, int t, int p) { static int r; for (r = 1; t; a = (long long)a * a % p, t >>= 1) if (t & 1) r = (long long)r * a % p; return r; } string to_string(string s) { return '"' + s + '"'; }; string to_string(const char *s) { return to_string(string(s)); } string to_string(bool f) { return f ? "true" : "false"; } template <class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <class T> string to_string(T v) { string s = "{", e = ""; for (auto &x : v) s += e + to_string(x), e = ", "; s += "}"; return s; } void debug_out() { cerr << endl; } template <class A, class... B> void debug_out(A x, B... y) { cerr << " " << to_string(x), debug_out(y...); } void scan() {} template <class A, class... B> void scan(A &a, B &...b) { gi(a), scan(b...); } template <class T> void read(T first, T last) { for (; first != last; ++first) gi(*first); } template <class T> void write(T first, T last) { for (; first != last; putc(++first == last ? '\n' : ' ')) print(*first); } template <class T> void show(T x) { print(x), putc('\n'); } template <class A, class... B> void show(A a, B... b) { print(a), putc(' '), show(b...); } template <class T> inline T abs(T x) { return x < 0 ? -x : x; } template <class T> bool chkmin(T &x, T y) { return y < x ? x = y, true : false; } template <class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } const int N = 2e5 + 5; int n, m, in[N], sg[N]; long long h[N], layer[N]; vector<int> adj[N]; int main() { int u, v; scan(n, m); read(h + 1, h + n + 1); queue<int> q; vector<int> topo; for (int i = 1; i <= m; ++i) scan(u, v), adj[u].emplace_back(v), in[v]++; for (int i = 1; i <= n; ++i) if (!in[i]) q.push(i); while (q.size()) { u = q.front(); topo.emplace_back(u); q.pop(); for (int v : adj[u]) if (!--in[v]) q.push(v); } reverse(topo.begin(), topo.end()); for (int x : topo) { set<int> nxt; for (int y : adj[x]) nxt.insert(sg[y]); while (nxt.count(sg[x])) ++sg[x]; layer[sg[x]] ^= h[x]; } for (u = n; u >= 0; --u) if (layer[u]) { puts("WIN"); for (v = 1; v <= n; ++v) if (sg[v] == u && (h[v] ^ layer[u]) < h[v]) break; h[v] ^= layer[u]; layer[u] = 0; for (int x : adj[v]) h[x] ^= layer[sg[x]], layer[sg[x]] = 0; write(h + 1, h + n + 1); exit(0); } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 200005; int n, m, u, v, a[MX], b[MX], ex[MX], x[MX]; vector<int> adj[MX], in[MX]; void dfs(int u) { if (b[u] != -1) return; for (int v : adj[u]) dfs(v); for (int v : adj[u]) ex[b[v]] = u; b[u] = 0; while (ex[b[u]] == u) b[u]++; in[b[u]].push_back(u); x[b[u]] ^= a[u]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i + 1]; while (m--) { cin >> u >> v; adj[u].push_back(v); } memset(b, -1, sizeof(b)); for (int i = 0; i < n; i++) dfs(i + 1); for (int i = n; i + 1; i--) if (x[i]) { int s = 0; for (int j = 0; j < 30; j++) if (x[i] & (1 << j)) s = j; for (int u : in[i]) if (a[u] & (1 << s)) { a[u] ^= x[i]; for (int v : adj[u]) ex[b[v]] = v; for (int j = 0; j < i; j++) a[ex[j]] ^= x[j]; break; } cout << "WIN" << '\n'; for (int i = 0; i < n; i++) cout << a[i + 1] << " "; cout << '\n'; return 0; } cout << "LOSE" << '\n'; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj(200001); int c[200001], mex[200001], h[200001], b[200001]; void DFS(int i) { for (int j : adj[i]) { if (mex[j] >= 0) { continue; } DFS(j); } for (int j : adj[i]) { c[mex[j]] = i; } int &k = mex[i]; for (k = 0; c[k] == i; ++k) ; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &h[i]); } while (m--) { int i, j; scanf("%d%d", &i, &j); adj[i].push_back(j); } for (int i = 1; i <= n; ++i) { mex[i] = -1; } for (int i = 1; i <= n; ++i) { if (mex[i] >= 0) { continue; } DFS(i); } for (int i = 1; i <= n; ++i) { b[mex[i]] ^= h[i]; } int root = 0; mex[root] = -1; for (int i = 1; i <= n; ++i) { if (mex[i] > mex[root] && ((b[mex[i]] ^ h[i]) < h[i])) { root = i; } } bool win = false; for (int i = 0; i <= mex[root] && !win; ++i) { win = (b[i] != 0); } if (!win) { printf("LOSE\n"); return 0; } c[mex[root]] = root; for (int j : adj[root]) { c[mex[j]] = j; } for (int i = 0; i <= mex[root]; ++i) { int j = c[i]; h[j] ^= b[i]; } printf("WIN\n"); for (int i = 1; i <= n; ++i) { printf("%d ", h[i]); } printf("\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ahowwogaw { int v, next; } _[1000005]; int head[1000005], tot = 1, zyl[200005], yihuo[1000005], a[1000005]; bool qwer[1000005]; int fyr(int iakioi) { if (zyl[iakioi] >= 0) { return zyl[iakioi]; } int i, ykb = 0, t; for (i = head[iakioi]; i; i = _[i].next) { ykb++; } bool have[ykb + 3]; memset(have, 0, sizeof(have)); for (i = head[iakioi]; i; i = _[i].next) { t = fyr(_[i].v); if (t <= ykb) { have[t] = 1; } } for (i = 0; have[i]; i++) { } zyl[iakioi] = i; return i; } int main() { memset(zyl, -1, sizeof(zyl)); int n, m, i, A, B, ykb, maxzyl = 0, maxid, win = -1; cin >> n >> m; for (i = 1; i <= n; i++) { scanf("%d", a + i); } for (i = 0; i < m; i++) { scanf("%d %d", &A, &B); _[tot].v = B; _[tot].next = head[A]; head[A] = tot++; } for (i = 1; i <= n; i++) { ykb = fyr(i); yihuo[ykb] ^= a[i]; if (ykb > maxzyl) { maxzyl = ykb; maxid = i; } } for (i = maxzyl; i >= 0; i--) { if (yihuo[i]) { win = i; break; } } if (win < 0) { cout << "LOSE"; return 0; } for (i = 1; i <= n; i++) { if (zyl[i] == win && (yihuo[zyl[i]] ^ a[i]) < a[i]) { a[i] ^= yihuo[zyl[i]]; win = i; break; } } for (i = head[win]; i; i = _[i].next) { if (!qwer[zyl[_[i].v]]) { a[_[i].v] ^= yihuo[zyl[_[i].v]]; qwer[zyl[_[i].v]] = 1; } } cout << "WIN" << endl; for (i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 200010; int n, m; int e, to[M], nxt[M], hd[N], deg[N]; int tag[N], sg[N], val[N], sum[N]; vector<int> vec[N]; void add(int x, int y) { to[++e] = y; nxt[e] = hd[x]; hd[x] = e; } void topo() { queue<int> q; for (int i = 1; i <= n; i++) if (deg[i] == 0) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = hd[u]; i; i = nxt[i]) { int v = to[i]; deg[v]--; if (deg[v] == 0) q.push(v); } for (int i = 0; i < vec[u].size(); i++) { int v = vec[u][i]; tag[sg[v]] = u; } while (tag[sg[u]] == u) sg[u]++; sum[sg[u]] ^= val[u]; } return; } void solve() { for (int i = n; i >= 0; i--) { if (!sum[i]) continue; int pos = 0; for (int j = 1; j <= n; j++) if (sg[j] == i && (val[j] ^ sum[i]) < val[j]) pos = j; val[pos] ^= sum[i]; for (int j = 0; j < vec[pos].size(); j++) { int v = vec[pos][j]; val[v] ^= sum[sg[v]]; sum[sg[v]] = 0; } puts("WIN"); for (int j = 1; j <= n; j++) printf("%d ", val[j]); puts(""); return; } puts("LOSE"); return; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &val[i]); for (int i = 1, u, v; i <= m; i++) { scanf("%d%d", &u, &v); vec[u].push_back(v); add(v, u); deg[u]++; } topo(); solve(); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; int const nmax = 200000; int v[1 + nmax]; std::vector<int> g[1 + nmax]; int mex(std::vector<int> aux) { std::sort(aux.begin(), aux.end()); aux.erase(std::unique(aux.begin(), aux.end()), aux.end()); for (int i = 0; i < aux.size(); i++) if (aux[i] != i) return i; return aux.size(); } int color[1 + nmax], dp[1 + nmax]; void dfs(int node) { std::vector<int> aux; for (int h = 0; h < g[node].size(); h++) { int to = g[node][h]; if (color[to] == -1) dfs(to); aux.push_back(color[to]); } color[node] = mex(aux); } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; for (int i = 1; i <= n; i++) std::cin >> v[i]; for (int i = 1; i <= n; i++) color[i] = -1; for (int i = 1; i <= m; i++) { int x, y; std::cin >> x >> y; g[x].push_back(y); } for (int i = 1; i <= n; i++) if (color[i] == -1) dfs(i); for (int i = 1; i <= n; i++) dp[color[i]] ^= v[i]; int result = 0; for (int i = 0; i <= n; i++) result += (dp[i] != 0); if (result == 0) std::cout << "LOSE\n"; else { for (int i = n; 0 <= i; i--) if (dp[i] != 0) { std::cout << "WIN\n"; for (int j = 1; j <= n; j++) if (color[j] == i) { if (0 < dp[i] && (v[j] ^ dp[i]) < v[j]) { v[j] ^= dp[i]; dp[i] ^= dp[i]; for (int h = 0; h < g[j].size(); h++) { int to = g[j][h]; if (0 < dp[color[to]]) { v[to] ^= dp[color[to]]; dp[color[to]] = 0; } } break; } } for (int j = 1; j <= n; j++) std::cout << v[j] << " "; std::cout << '\n'; return 0; } } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX = (int)2e5 + 5; int n, m; vector<int> v[MAX]; int h[MAX]; set<int> s[MAX]; set<int> t[MAX]; int dep[MAX]; int xors[MAX]; vector<pair<int, int> > mxx[MAX]; int bio[MAX]; int p[1000]; void dfs(int cx) { if (bio[cx]) return; bio[cx] = 1; for (int i = (0), _for = (1000); i < _for; ++i) p[i] = 0; for (auto first : v[cx]) { p[dep[first]] = 1; } for (int i = (0), _for = (1000); i < _for; ++i) { if (!p[i]) { dep[cx] = i; xors[i] ^= h[cx]; mxx[i].push_back({h[cx], cx}); break; } } for (auto nx : t[cx]) { s[nx].erase(cx); if (s[nx].empty()) dfs(nx); } } int find_cx(int i) { int xr = xors[i]; for (auto cx : mxx[i]) { if ((cx.first ^ xr) <= cx.first) return cx.second; } return -1; } int main() { scanf("%d%d", &n, &m); for (int i = (0), _for = (n); i < _for; ++i) scanf("%d", h + i); for (int i = (0), _for = (m); i < _for; ++i) { int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); s[a].insert(b); t[b].insert(a); } for (int i = (0), _for = (n); i < _for; ++i) if (s[i].empty()) dfs(i); for (int i = 999; i >= 0; --i) if (xors[i]) { puts("WIN"); int cx = find_cx(i); h[cx] ^= xors[i]; for (auto nx : v[cx]) { int d = dep[nx]; h[nx] ^= xors[d]; xors[d] = 0; } for (int i = (0), _for = (n); i < _for; ++i) { printf("%d ", h[i]); } printf("\n"); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> const int N = 200005; using namespace std; long long n, m, num[N], sy[N], ds[N], bj[N], sum[N]; vector<long long> to[N], pre[N]; queue<long long> que; int main() { long long i, j, t, p, q; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%lld", &num[i]); for (i = 1; i <= m; i++) { scanf("%lld%lld", &p, &q); pre[q].push_back(p); to[p].push_back(q); ds[p]++; } for (i = 1; i <= n; i++) if (!ds[i]) que.push(i); while (!que.empty()) { q = que.front(); que.pop(); for (i = 0; i < pre[q].size(); i++) { t = pre[q][i]; ds[t]--; if (!ds[t]) que.push(t); } for (i = 0; i < to[q].size(); i++) { t = to[q][i]; bj[sy[t]] = q; } for (i = 0; bj[i] == q; i++) ; sy[q] = i; sum[sy[q]] ^= num[q]; } for (i = n; i >= 0; i--) { if (!sum[i]) continue; puts("WIN"); for (j = 1; j <= n; j++) if (sy[j] == i && (num[j] ^ sum[i]) < num[j]) break; q = j, num[q] ^= sum[i]; for (j = 0; j < to[q].size(); j++) { t = to[q][j]; if (sum[sy[t]] && bj[sy[t]] != -1) { bj[sy[t]] = -1; num[t] ^= sum[sy[t]]; } } for (i = 1; i <= n; i++) printf("%lld ", num[i]); return 0; } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const int N = 2e5 + 5; long long h[N], s[N]; int w[N]; vector<int> g[N]; bool used[N]; void dfs(int node) { if (used[node]) return; used[node] = 1; vector<int> t; for (int to : g[node]) { dfs(to); t.push_back(w[to]); } sort(t.begin(), t.end()); t.erase(unique(t.begin(), t.end()), t.end()); while (w[node] < t.size() && t[w[node]] == w[node]) w[node]++; s[w[node]] ^= h[node]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; g[a].push_back(b); } for (int i = 0; i < n; i++) { dfs(i); } int mx = -1; for (int i = 0; i < n; i++) { if (s[i] != 0) { mx = max(mx, i); } } if (mx != -1) { cout << "WIN\n"; for (int i = 0; i < n; i++) { if (w[i] == mx && (s[mx] ^ h[i]) < h[i]) { h[i] = s[mx] ^ h[i]; for (int to : g[i]) { if (s[w[to]] != 0) { h[to] = s[w[to]] ^ h[to]; s[w[to]] = 0; } } break; } } for (int i = 0; i < n; i++) cout << h[i] << " "; } else { cout << "LOSE"; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, m, h[N], nxt[N], adj[N], rd[N], u, v, t, id[N], mx, q[N], top1, top2; long long a[N], val[N]; bool vs[N]; inline void add() { nxt[++t] = h[u], h[u] = t, adj[t] = v; } int main() { scanf("%d%d", &n, &m); register int i; for (i = 1; i <= n; ++i) scanf("%lld", &a[i]); while (m--) scanf("%d%d", &u, &v), add(), ++rd[v]; for (i = 1; i <= n; ++i) if (!rd[i]) q[++top2] = i; while (top1 < top2) for (i = h[u = q[++top1]]; i; i = nxt[i]) if (!--rd[adj[i]]) q[++top2] = adj[i]; for (i = n; i; --i) { for (v = h[u = q[i]]; v; v = nxt[v]) vs[id[adj[v]]] = 1; while (vs[id[u]]) ++id[u]; id[u] > mx ? mx = id[u] : 0, val[id[u]] ^= a[u]; for (v = h[u]; v; v = nxt[v]) vs[id[adj[v]]] = 0; } for (i = mx; ~i; --i) if (val[i]) break; if (i < 0) return puts("LOSE"), 0; puts("WIN"), u = i; for (i = 1; i <= n; ++i) if (id[i] == u) { if ((val[id[i]] ^ a[i]) > a[i]) continue; a[i] ^= val[id[i]], val[id[i]] = 0; for (v = h[i]; v; v = nxt[v]) a[adj[v]] ^= val[id[adj[v]]], val[id[adj[v]]] = 0; } for (i = 1; i <= n; ++i) printf("%lld ", a[i]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 200200; vector<int> g[N]; int ord[N]; int ordSz; bool used[N]; int n, m; int a[N]; int b[N]; int c[N]; bool mex[N]; void dfs(int v) { used[v] = 1; for (int u : g[v]) { if (used[u]) continue; dfs(u); } ord[ordSz++] = v; } void printAns(int v) { a[v] ^= c[b[v]]; c[b[v]] = 0; for (int u : g[v]) { a[u] ^= c[b[u]]; c[b[u]] = 0; } for (int i = 0; i < n; i++) printf("%d ", a[i]); printf("\n"); } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &a[i]); while (m--) { int v, u; scanf("%d%d", &v, &u); v--; u--; g[v].push_back(u); } for (int i = 0; i < n; i++) { if (used[i]) continue; dfs(i); } for (int i = 0; i < n; i++) { int v = ord[i]; for (int j = 0; j <= (int)g[v].size(); j++) mex[j] = 0; for (int u : g[v]) mex[b[u]] = 1; b[v] = 0; while (mex[b[v]]) b[v]++; } for (int i = 0; i < n; i++) c[b[i]] ^= a[i]; int mx = -1; for (int i = 0; i < n; i++) { if (c[i] != 0) mx = i; } if (mx == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (int v = 0; v < n; v++) { if (b[v] != mx) continue; if ((a[v] ^ c[mx]) > a[v]) continue; printAns(v); return 0; } throw; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> struct city { int estart; long long int tax; bool visited; int mex; } v[200003]; struct edge { int enext, to; } e[200003]; int n, m; void dfs(int i) { v[i].visited = true; std::vector<int> temp; for (int j = v[i].estart; j != -1; j = e[j].enext) { int to = e[j].to; if (!v[to].visited) { dfs(to); } temp.push_back(v[to].mex); } std::sort(temp.begin(), temp.end()); int mex = 0; for (int i = 0; i < temp.size(); ++i) { if (temp[i] > mex) break; if (temp[i] == mex) ++mex; } v[i].mex = mex; } long long int w[200003]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%I64d", &v[i].tax); v[i].estart = -1; } for (int i = 0; i < m; ++i) { int a, b; scanf("%d%d", &a, &b); --a, --b; e[i].enext = v[a].estart; e[i].to = b; v[a].estart = i; } int maxm = 0; for (int i = 0; i < n; ++i) { if (!v[i].visited) { dfs(i); } if (v[i].mex > maxm) maxm = v[i].mex; w[v[i].mex] ^= v[i].tax; } int i = maxm; while (i >= 0 && w[i] == 0) --i; if (i == -1) { printf("LOSE\n"); return 0; } int x = -1; for (int j = 0; j < n; ++j) if (v[j].mex == i && (v[j].tax ^ w[i]) < v[j].tax) { x = j; break; } v[x].tax ^= w[i]; w[i] = 0; for (int j = v[x].estart; j != -1; j = e[j].enext) { int to = e[j].to; if (v[to].mex < i) { v[to].tax ^= w[v[to].mex]; w[v[to].mex] = 0; } } printf("WIN\n"); for (int i = 0; i < n; ++i) { printf("%I64d ", v[i].tax); } printf("\n"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct node { int to, nxt; } edge[200100]; int val[200100], maxn, cnt, head[200100], n, m; long long h[200100], X[710]; void addedge(int x, int y) { edge[++cnt].to = y; edge[cnt].nxt = head[x]; head[x] = cnt; } void dfs(int x) { if (val[x] != -1) return; bool vis[710] = {0}; for (int i = head[x]; i; i = edge[i].nxt) { int upup = edge[i].to; dfs(upup); vis[val[upup]] = 1; } for (int i = 0;; i++) if (!vis[i]) { val[x] = i; break; } maxn = max(maxn, val[x]); X[val[x]] ^= h[x]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); memset(val, -1, sizeof(val)); for (int i = 1, x, y; i <= m; i++) { scanf("%d%d", &x, &y); addedge(x, y); } for (int i = 1; i <= n; i++) dfs(i); for (int i = maxn; i >= 0; i--) if (X[i]) { puts("WIN"); for (int j = 1; j <= n; j++) if (val[j] == i && (h[j] ^ X[i]) < h[j]) { h[j] ^= X[i]; X[i] = 0; for (int k = head[j]; k; k = edge[k].nxt) { int upup = edge[k].to; if (X[val[upup]]) { h[upup] = X[val[upup]] ^ h[upup]; X[val[upup]] = 0; } } break; } for (int j = 1; j <= n; j++) printf("%lld ", h[j]); puts(""); return 0; } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; int n, m; const int NN = 200011; int h[NN]; VI adj[NN]; map<int, int> g; int tot[NN]; inline int get(int u) { if (g.count(u)) return g[u]; map<int, int> vst; for (int v : adj[u]) { vst[get(v)] = 1; } for (int i = 0;; i++) if (vst.count(i) == 0) return g[u] = i; } int solve() { cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", h + i); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); } for (int i = 1; i <= n; i++) tot[get(i)] ^= h[i]; int id = n; while (id >= 0 and tot[id] == 0) id--; if (id < 0) return puts("LOSE"); for (int i = 1; i <= n; i++) if (g[i] == id) { int u = tot[id] ^ h[i]; if (u < h[i]) { h[i] = u; for (int v : adj[i]) { h[v] ^= tot[g[v]]; tot[g[v]] = 0; } puts("WIN"); for (int i = 1; i <= n; i++) printf("%d ", h[i]); return 0; } } } int main() { solve(); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, mod = 1e9 + 7; const long long inf = 1e18; int a[maxn]; bool mark[maxn]; vector<int> v[maxn], vec; vector<int> vv[maxn]; int p[maxn], xr[maxn], C; void dfs(int u) { mark[u] = 1; for (int y : v[u]) { if (!mark[y]) dfs(y); } vec.push_back(u); } void add(int u) { for (int y : v[u]) { mark[p[y]] = 1; } for (int i = 0; i <= C; i++) { if (mark[i] == 0) { p[u] = i; vv[i].push_back(u); xr[i] ^= a[u]; if (i == C) C++; break; } } for (int y : v[u]) { mark[p[y]] = 0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; v[x].push_back(y); } for (int i = 1; i <= n; i++) { if (!mark[i]) dfs(i); } memset(mark, 0, sizeof mark); for (int i = 0; i < n; i++) { add(vec[i]); } int lst = -1; for (int i = 0; i < C; i++) { if (xr[i] != 0) lst = i; } if (lst == -1) return cout << "LOSE\n", 0; int bt = 31 - __builtin_clz(xr[lst]), who = 0; for (int u : vv[lst]) { if ((((a[u]) >> (bt)) & 1)) { who = u; } } assert(who != -1); a[who] ^= xr[lst]; for (int y : v[who]) { if (mark[p[y]]) continue; mark[p[y]] = 1; a[y] ^= xr[p[y]]; } cout << "WIN\n"; for (int i = 1; i <= n; i++) { cout << a[i] << " "; } return cout << endl, 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long double eps = 0.00000000001; int n, m; vector<int> E[300000]; int tab[300000]; int vis[300000]; int levelId[300000]; int levelXor[300000]; void dfs(int a) { vis[a] = true; vector<int> L; for (int v : E[a]) { if (!vis[v]) { dfs(v); } L.push_back(levelId[v]); } L.push_back(inf); sort(L.begin(), L.end()); L.resize(unique(L.begin(), L.end()) - L.begin()); int level = 0; while (level == L[level]) { level++; } levelId[a] = level; levelXor[level] ^= tab[a]; } void countMove(int level) { int high = 0; for (int i = 0; i <= 30; i++) { if (((1 << i) & levelXor[level]) != 0) { high = i; } } int a = -1; for (int i = 1; i <= n; i++) { if (levelId[i] == level) { if (((1 << high) & tab[i]) != 0) { a = i; } } } tab[a] ^= levelXor[level]; levelXor[level] = 0; for (int v : E[a]) { if (levelXor[levelId[v]] != 0) { tab[v] ^= levelXor[levelId[v]]; levelXor[levelId[v]] = 0; } } } void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> tab[i]; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; E[u].push_back(v); } for (int i = 1; i <= n; i++) { if (!vis[i]) { dfs(i); } } int level = -1; for (int i = 0; i <= n; i++) { if (levelXor[i] != 0) { level = i; } } if (level == -1) { cout << "LOSE" << "\n"; return; } countMove(level); cout << "WIN" << "\n"; for (int i = 1; i <= n; i++) { cout << tab[i] << " "; } cout << "\n"; } void clear() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int z = 1; for (int i = 0; i < z; i++) { solve(); clear(); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m; vector<int> edges[N]; bool vis[N]; int mex[N]; int getMex(int u) { if (~mex[u]) return mex[u]; vector<bool> vis(edges[u].size() + 1, false); for (int v : edges[u]) { vis[min(getMex(v), (int)edges[u].size())] = true; } mex[u] = 0; while (vis[mex[u]]) ++mex[u]; return mex[u]; } long long h[N]; long long x[N]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) scanf("%lld", &h[i]); for (int i = 0; i < m; ++i) { int u, v; scanf("%d %d", &u, &v); edges[--u].push_back(--v); } memset(mex, -1, sizeof mex); for (int i = 0; i < n; ++i) { x[getMex(i)] ^= h[i]; } for (int i = n - 1; i >= 0; --i) { if (x[i] == 0) continue; printf("WIN\n"); for (int j = 0; j < n; ++j) { if (getMex(j) != i) continue; if ((x[i] ^ h[j]) >= h[j]) continue; h[j] = (x[i] ^ h[j]); vector<bool> vis(i + 1, false); for (int v : edges[j]) { if (getMex(v) < i && !vis[getMex(v)]) { h[v] = (x[getMex(v)] ^ h[v]); vis[getMex(v)] = true; } } break; } for (int j = 0; j < n; ++j) printf("%lld ", h[j]); printf("\n"); return 0; } printf("LOSE\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> const long long INF = 1e18; const int inf = 1e9; const int MAXN = 3e5 + 200; const long double eps = 1e-16; const long double pi = acos(-1.0); using namespace std; int dx[] = {0, 1, 1, 1, -1, -1, -1}; int dy[] = {1, -1, 0, 1, -1, 0, 1, -1}; int n, m; long long a[MAXN], H[MAXN]; int M[MAXN]; vector<int> g[MAXN]; void dfs(int v) { set<int> st; int kol = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (M[to]) { st.insert(M[to]); continue; } dfs(to); st.insert(M[to]); } while (st.find(kol) != st.end()) kol++; M[v] = kol; } void solve() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; g[x].push_back(y); } for (int i = 0; i < n; i++) if (!M[i]) dfs(i); for (int i = 0; i < n; i++) H[M[i]] ^= a[i]; int top = 0; for (int i = 0; i < MAXN; i++) if (H[i]) top = i; if (top == 0) { cout << "LOSE\n"; return; } cout << "WIN\n"; int ind = -1; for (int i = 0; i < n; i++) { if (M[i] == top) { if ((a[i] ^ H[top]) < a[i]) { ind = i; break; } } } a[ind] ^= H[top]; for (int i = 0; i < g[ind].size(); i++) { int to = g[ind][i]; H[M[to]] ^= a[to]; a[to] = H[M[to]]; H[M[to]] = 0; } for (int i = 0; i < n; i++) cout << a[i] << " "; } int main() { ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); int step; step = 1; for (int i = 1; i <= step; i++) { solve(); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, h[200012], cnt = 0, a[200012], f[200012], b[200012], c[200012]; bool vis[200012]; struct Edge { int to, next; } e[200012]; inline void AddEdge(int x, int y) { e[++cnt] = (Edge){y, h[x]}; h[x] = cnt; } void dfs(int x) { if (vis[x]) return; vis[x] = 1; int i; for (i = h[x]; i; i = e[i].next) dfs(e[i].to); for (i = h[x]; i; i = e[i].next) b[f[e[i].to]] = x; for (f[x] = 0; b[f[x]] == x; ++f[x]) ; } int main() { scanf("%d%d", &n, &m); int i, x, y, p, o = 0; for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); AddEdge(x, y); } for (i = 1; i <= n; i++) dfs(i), c[f[i]] ^= a[i]; for (i = n; i >= 0; i--) if (c[i]) break; p = i; if (p == (-1)) { printf("LOSE"); return 0; } printf("WIN\n"); for (x = 1; x <= n; x++) if ((f[x] == p) && ((a[x] ^ c[p]) < a[x])) a[x] ^= c[p], c[p] = 0, o = x; for (i = h[o]; i; i = e[i].next) if (f[y = e[i].to] < p) a[y] ^= c[f[y]], c[f[y]] = 0; for (x = 1; x <= n; x++) printf("%d ", a[x]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int gi() { int x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * o; } vector<int> E[N]; int n, m, h[N], deg[N], vis[N], sg[N], sum[N], sq[N], tt = 0; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) h[i] = gi(); for (int i = 1, u, v; i <= m; i++) u = gi(), ++deg[v = gi()], E[u].push_back(v); queue<int> q; for (int i = 1; i <= n; i++) if (!deg[i]) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); sq[++tt] = u; for (auto v : E[u]) if (!--deg[v]) q.push(v); } for (int i = tt, u; i; i--) { u = sq[i]; for (auto v : E[u]) vis[sg[v]] = u; for (int j = 0;; j++) if (vis[j] ^ u) { sum[sg[u] = j] ^= h[u]; break; } } for (int i = n - 1; ~i; i--) if (sum[i]) { puts("WIN"); for (int u = 1; u <= n; u++) if (sg[u] == i && (h[u] ^ sum[i]) < h[u]) { h[u] ^= sum[i]; for (auto v : E[u]) h[v] ^= sum[sg[v]], sum[sg[v]] = 0; for (int v = 1; v <= n; v++) cout << h[v] << ' '; return 0; } } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> int h[200010], SG[200010], sum[200010]; int fir[200010], nxt[200010], dis[200010], id; void link(int a, int b) { nxt[++id] = fir[a], fir[a] = id, dis[id] = b; } int que[200010], hd = 1, tl = 1, in[200010]; int c[200010]; int main() { int n, m, a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &h[i]); while (m--) scanf("%d%d", &a, &b), link(a, b), ++in[b]; for (int i = 1; i <= n; ++i) if (!in[i]) que[tl++] = i; while (hd ^ tl) for (int i = fir[que[hd++]]; i; i = nxt[i]) if (!--in[dis[i]]) que[tl++] = dis[i]; for (int o = n, x; o; --o) { x = que[o]; for (int i = fir[x]; i; i = nxt[i]) ++c[SG[dis[i]]]; while (c[SG[x]]) ++SG[x]; sum[SG[x]] ^= h[x]; for (int i = fir[x]; i; i = nxt[i]) --c[SG[dis[i]]]; } for (int i = n, x; ~i; --i) if (sum[i]) { for (int j = 1; j <= n; ++j) if (SG[j] == i && h[j] > (h[j] ^ sum[i])) x = j; h[x] ^= sum[i]; for (int j = fir[x]; j; j = nxt[j]) h[dis[j]] ^= sum[SG[dis[j]]], sum[SG[dis[j]]] = 0; puts("WIN"); for (int j = 1; j <= n; ++j) printf("%d ", h[j]); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct edge { int to, nxxt; } e[200005 << 1]; queue<int> q; vector<int> v[200005]; bool vis[200005]; int head[200005], cnt = 1, n, m, a[200005], id[200005], b[200005], tot, rd[200005], tb[200005], xr[200005], mx; inline void ins(int u, int v) { e[cnt] = (edge){v, head[u]}; head[u] = cnt++; } int main() { memset(id, -1, sizeof(id)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); ins(x, y); rd[y]++; } for (int i = 1; i <= n; i++) if (!rd[i]) q.push(i); while (!q.empty()) { int a1 = q.front(); q.pop(); b[++tot] = a1; for (int i = head[a1]; i; i = e[i].nxxt) { int j = e[i].to; rd[j]--; if (!rd[j]) q.push(j); } } for (int i = n; i; i--) { int x = b[i]; tot = 0; for (int j = head[x]; j; j = e[j].nxxt) { tb[++tot] = id[e[j].to]; } sort(tb + 1, tb + 1 + tot); if (tb[1] > 0 || !tot) id[x] = 0; else { for (int j = 1; j < tot; j++) if (tb[j] + 1 < tb[j + 1]) { id[x] = tb[j] + 1; break; } if (id[x] < 0) id[x] = tb[tot] + 1; } } for (int i = 1; i <= n; i++) xr[id[i]] ^= a[i]; bool flag = false; for (int i = 0; i <= n; i++) if (xr[i]) { flag = true; break; } if (!flag) { puts("LOSE"); return 0; } puts("WIN"); for (int i = 1; i <= n; i++) mx = max(mx, id[i]); for (int i = 1; i <= n; i++) v[id[i]].push_back(i); for (int i = mx; ~i; i--) if (xr[i]) { int te; for (int j = 0; j < v[i].size(); j++) { int to = v[i][j]; if ((xr[i] ^ a[to]) < a[to]) { te = v[i][j]; break; } } a[te] ^= xr[i]; for (int j = head[te]; j; j = e[j].nxxt) { int to = e[j].to; if (!vis[id[to]]) { a[to] ^= xr[id[to]]; vis[id[to]] = 1; } } break; } for (int i = 1; i <= n; i++) printf("%d ", a[i]); puts(""); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct fastio { char s[100000]; int it, len; fastio() { it = len = 0; } inline char get() { if (it < len) return s[it++]; it = 0; len = fread(s, 1, 100000, stdin); if (len == 0) return EOF; else return s[it++]; } bool notend() { char c = get(); while (c == ' ' || c == '\n') c = get(); if (it > 0) it--; return c != EOF; } } _buff; inline long long getnum() { long long r = 0; bool ng = 0; char c; c = _buff.get(); while (c != '-' && (c < '0' || c > '9')) c = _buff.get(); if (c == '-') ng = 1, c = _buff.get(); while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get(); return ng ? -r : r; } template <class T> inline void putnum(T x) { if (x < 0) putchar('-'), x = -x; register short a[20] = {}, sz = 0; while (x) a[sz++] = x % 10, x /= 10; if (sz == 0) putchar('0'); for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]); } inline char getreal() { char c = _buff.get(); while (c <= 32) c = _buff.get(); return c; } long long qpow(long long x, long long k) { return k == 0 ? 1 : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod; } const int maxn = 200111; int n, m; int mex[maxn], a[maxn]; bool hs[maxn]; int xsum[maxn]; vector<int> con[maxn]; void dfs(int x) { if (mex[x] != -1) return; for (auto u : con[x]) { dfs(u); } for (auto u : con[x]) hs[mex[u]] = 1; mex[x] = 0; while (hs[mex[x]]) mex[x]++; for (auto u : con[x]) hs[mex[u]] = 0; xsum[mex[x]] ^= a[x]; } void output_ans(int L) { static int ans[maxn]; for (int i = 1; i <= n; i++) ans[i] = a[i]; int x = -1; for (int i = 1; i <= n; i++) { if (mex[i] == L) { if ((xsum[L] ^ a[i]) < a[i]) { x = i; break; } } } ans[x] = xsum[L] ^ a[x]; for (auto u : con[x]) { if (!hs[mex[u]]) { hs[mex[u]] = true; ans[u] = xsum[mex[u]] ^ a[u]; } } for (int i = 1; i <= n; i++) putnum(ans[i]), putchar(' '); } int main() { n = getnum(), m = getnum(); for (int i = 1; i <= n; i++) a[i] = getnum(); for (int i = 1; i <= m; i++) { int x, y; x = getnum(), y = getnum(); con[x].push_back(y); } memset(mex, -1, sizeof(mex)); for (int i = 1; i <= n; i++) { if (mex[i] == -1) dfs(i); } for (int i = n; i >= 0; i--) { if (xsum[i] != 0) { puts("WIN"); output_ans(i); return 0; } } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int c = 200002; queue<int> q; vector<int> sz[c], s[c], f[c]; long long n, m, be[c], me[c], t[c], xo[c], maxi; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> t[i], f[i].push_back(c); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; sz[a].push_back(b), s[b].push_back(a); be[a]++; } for (int i = 1; i <= n; i++) if (!be[i]) q.push(i); while (q.size() > 0) { int id = q.front(), pr = 0; q.pop(); sort(f[id].begin(), f[id].end()); for (int i = 0; i < f[id].size(); i++) { if (f[id][i] - pr > 1) { pr++; xo[pr] ^= t[id]; me[id] = pr; break; } pr = f[id][i]; } for (int i = 0; i < s[id].size(); i++) { int x = s[id][i]; f[x].push_back(me[id]); be[x]--; if (!be[x]) q.push(x); } } for (int i = 1; i <= n; i++) { if (xo[i]) maxi = i; } if (!maxi) { cout << "LOSE\n"; } else { cout << "WIN\n"; for (int i = 1; i <= n; i++) { if (me[i] == maxi && (t[i] ^ xo[me[i]]) < t[i]) { for (int j = 0; j < sz[i].size(); j++) { int x = sz[i][j]; if (xo[me[x]]) { t[x] ^= xo[me[x]]; xo[me[x]] = 0; } } t[i] ^= xo[maxi]; xo[maxi] = 0; break; } } for (int i = 1; i <= n; i++) { cout << t[i] << " "; } cout << "\n"; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int NN = 200011; vector<int> adj[NN]; int n, m; int h[NN]; int xo[NN]; int g[NN]; int ans[NN]; int vst[NN]; int runs = 1; int calc(int u) { if (~g[u]) return g[u]; for (int v : adj[u]) calc(v); runs++; for (int v : adj[u]) vst[g[v]] = runs; for (int i = 0;; i++) if (vst[i] ^ runs) return g[u] = i; } int solve() { memset(g, -1, sizeof g); cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", h + i), ans[i] = h[i]; for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); } for (int i = 1; i <= n; i++) xo[calc(i)] ^= h[i]; int id = -1; for (int i = 0; i <= n; i++) if (xo[i]) id = i; if (id == -1) return puts("LOSE"); puts("WIN"); int now = -1; for (int i = 1; i <= n; i++) if (g[i] == id) { int u = xo[id] ^ h[i]; if (u < h[i]) { ans[i] = u; now = i; break; } } assert(now != -1); for (int u : adj[now]) ans[u] = xo[g[u]] ^ h[u], xo[g[u]] = 0; for (int i = 1; i <= n; i++) printf("%d ", ans[i]); } int main() { solve(); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, SG[200005], Mx, h[200005], sum[200005]; bool vis[200005]; int fir[200005], nxt[200005], to[200005], tot; inline void line(int x, int y) { nxt[++tot] = fir[x]; fir[x] = tot; to[tot] = y; } void dfs(int u) { for (int i = fir[u]; i; i = nxt[i]) if (!SG[to[i]]) dfs(to[i]); for (int i = fir[u]; i; i = nxt[i]) vis[SG[to[i]]] = 1; int x = 1; while (vis[x] == 1) x++; Mx = max(Mx, SG[u] = x), sum[x] ^= h[u]; for (int i = fir[u]; i; i = nxt[i]) vis[SG[to[i]]] = 0; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1, x, y; i <= m; i++) scanf("%d%d", &x, &y), line(x, y); for (int i = 1; i <= n; i++) if (!SG[i]) dfs(i); for (int k = Mx, id = 0; k >= 1; k--) if (sum[k]) { for (int i = 1; i <= n; i++) if (SG[i] == k && (h[i] ^ sum[k]) < h[i]) id = i; h[id] ^= sum[k]; for (int i = fir[id]; i; i = nxt[i]) if (!vis[SG[to[i]]]) h[to[i]] ^= sum[SG[to[i]]], vis[SG[to[i]]] = 1; puts("WIN"); for (int i = 1; i <= n; i++) printf("%d%c", h[i], i == n ? 10 : 32); return 0; } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using std::cerr; using std::endl; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int MAXN = 200005; int n, m, ecnt, head[MAXN], deg[MAXN]; int a[MAXN], sg[MAXN], sum[MAXN]; std::vector<int> ie[MAXN]; struct Edge { int to, nxt; } e[MAXN]; inline void add_edge(int bg, int ed) { ++ecnt; e[ecnt].to = ed; e[ecnt].nxt = head[bg]; head[bg] = ecnt; } std::queue<int> q; int vis[MAXN]; void topo() { while (!q.empty()) q.pop(); for (int i = (1); i <= (n); ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int x = q.front(); q.pop(); for (int i = head[x]; i; i = e[i].nxt) { int ver = e[i].to; vis[sg[ver]] = x; } for (int i = (0); i <= (1e9); ++i) { if (vis[i] != x) { sg[x] = i; break; } } sum[sg[x]] ^= a[x]; for (int i = (0); i <= ((int)ie[x].size() - 1); ++i) { int ver = ie[x][i]; --deg[ver]; if (!deg[ver]) q.push(ver); } } } int main() { n = read(), m = read(); for (int i = (1); i <= (n); ++i) a[i] = read(); for (int i = (1); i <= (m); ++i) { int u = read(), v = read(); add_edge(u, v); ie[v].push_back(u); ++deg[u]; } topo(); int max_sg = -1; for (int i = (n - 1); i >= (0); --i) { if (sum[i]) { max_sg = i; break; } } if (max_sg == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (int i = (1); i <= (n); ++i) { if (sg[i] == max_sg && (a[i] ^ sum[max_sg]) < a[i]) { a[i] ^= sum[max_sg]; sum[max_sg] = 0; for (int j = head[i]; j; j = e[j].nxt) { int ver = e[j].to; a[ver] ^= sum[sg[ver]]; sum[sg[ver]] = 0; } } } for (int i = (1); i <= (n); ++i) printf("%d ", a[i]); putchar('\n'); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } if (flag) x = -x; } int n, m; int v[200010], w[200010], s[200010], d[200010], tag[200010]; vector<int> ve[200010]; struct edge { int to, nxt; } e[200010]; int head[200010], edge_cnt; void add(int from, int to) { e[++edge_cnt] = {to, head[from]}, head[from] = edge_cnt; } void topo() { queue<int> q; for (int i = 1; i <= n; ++i) if (!d[i]) q.push(i); while (!q.empty()) { int x = q.front(); q.pop(); for (int i = head[x]; i; i = e[i].nxt) if (--d[e[i].to] == 0) q.push(e[i].to); for (int i = 0; i < ve[x].size(); ++i) tag[w[ve[x][i]]] = x; while (tag[w[x]] == x) w[x]++; s[w[x]] ^= v[x]; } } int main() { read(n), read(m); for (int i = 1; i <= n; ++i) read(v[i]); for (int i = 1; i <= m; ++i) { int x, y; read(x), read(y); ve[x].push_back(y), add(y, x), d[x]++; } topo(); for (int i = n; i >= 0; --i) { if (!s[i]) continue; int pos; for (int j = 1; j <= n; ++j) if (w[j] == i && v[j] > (v[j] ^ s[i])) pos = j; v[pos] ^= s[i]; for (int j = 0; j < ve[pos].size(); ++j) { int x = ve[pos][j]; v[x] ^= s[w[x]], s[w[x]] = 0; } puts("WIN"); for (int j = 1; j <= n; ++j) printf("%d ", v[j]); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int c = 200002; queue<int> q; vector<int> sz[c], s[c], f[c]; long long n, m, be[c], me[c], t[c], xo[c], maxi; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> t[i], f[i].push_back(c); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; sz[a].push_back(b), s[b].push_back(a); be[a]++; } for (int i = 1; i <= n; i++) if (!be[i]) q.push(i); while (q.size() > 0) { int id = q.front(), pr = 0; q.pop(); sort(f[id].begin(), f[id].end()); for (int i = 0; i < f[id].size(); i++) { if (f[id][i] - pr > 1) { pr++; xo[pr] ^= t[id]; me[id] = pr; break; } pr = f[id][i]; } for (int i = 0; i < s[id].size(); i++) { int x = s[id][i]; f[x].push_back(me[id]); be[x]--; if (!be[x]) q.push(x); } } for (int i = 1; i <= n; i++) { if (xo[i]) maxi = i; } if (!maxi) { cout << "LOSE\n"; } else { cout << "WIN\n"; for (int i = 1; i <= n; i++) { if (me[i] == maxi && (t[i] ^ xo[me[i]]) < t[i]) { for (int j = 0; j < sz[i].size(); j++) { int x = sz[i][j]; if (xo[me[x]]) { t[x] ^= xo[me[x]]; xo[me[x]] = 0; } } t[i] ^= xo[maxi]; xo[maxi] = 0; break; } } for (int i = 1; i <= n; i++) { cout << t[i] << " "; } cout << "\n"; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long ver[N << 1], nxt[N << 1], head[N], deg[N], tot; long long h[N], st[N], vis[N << 1], id[N], t[N << 1], Max, top, n, m; queue<long long> q; inline long long read() { long long x = 0, ff = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * ff; } void add(long long x, long long y) { ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; deg[y]++; } signed main() { n = read(); m = read(); for (long long i = 1; i <= n; i++) h[i] = read(); for (long long i = 1; i <= m; i++) { long long u, v; u = read(); v = read(); add(u, v); } for (long long i = 1; i <= n; i++) if (!deg[i]) q.push(i); while (q.size()) { long long x = q.front(); q.pop(); st[++top] = x; for (long long i = head[x]; i; i = nxt[i]) { long long y = ver[i]; deg[y]--; if (!deg[y]) q.push(y); } } for (long long i = top; i >= 1; i--) { for (long long j = head[i]; j; j = nxt[j]) vis[id[ver[j]]] = 1; for (long long nw = 0;; nw++) { if (!vis[nw]) { id[i] = nw; break; } } t[id[i]] ^= h[i]; Max = max(Max, id[i]); for (long long j = head[i]; j; j = nxt[j]) vis[id[ver[j]]] = 0; } long long maxx = -1; for (long long i = 0; i <= Max; i++) { if (t[i]) maxx = max(maxx, i); } if (maxx == -1) { puts("LOSE"); return 0; } for (long long i = 1; i <= n; i++) { if (!t[id[i]]) continue; if (id[i] == maxx && (t[id[i]] ^ h[i]) < h[i]) { h[i] ^= t[id[i]]; for (long long j = head[i]; j; j = nxt[j]) { long long y = ver[j]; if (t[id[y]]) { h[y] ^= t[id[y]]; } } break; } } puts("WIN"); for (long long i = 1; i <= n; i++) printf("%lld ", h[i]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct Graph { vector<int> toposort() const { auto deg = vector<int>(size(), 0); auto que = vector<int>(); for (auto v = 0; v < size(); ++v) for (auto u : edges[v]) ++deg[u]; for (auto v = 0; v < size(); ++v) if (deg[v] == 0) que.push_back(v); for (auto i = 0; i < (int)que.size(); ++i) for (auto u : edges[que[i]]) if (--deg[u] == 0) que.push_back(u); return que; } Graph(int n) : edges(n) {} void addEdge1(int a, int b) { edges[a].push_back(b); } void addEdge2(int a, int b) { addEdge1(a, b); addEdge1(b, a); } int size() const { return (int)edges.size(); } vector<vector<int>> edges; }; template <typename T> T load() { T r; cin >> r; return r; } template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; } Graph loadEdges(int n, int m) { auto g = Graph(n); while (m-- > 0) { auto v = load<int>() - 1; auto u = load<int>() - 1; g.addEdge1(v, u); } return g; } template <typename T, typename F> int lastIf(const vector<T>& xs, F f) { for (auto i = (int)xs.size() - 1; i >= 0; --i) if (f(xs[i])) return i; return -1; } int mex(const vector<int>& xs) { auto in = vector<bool>(xs.size(), false); for (auto x : xs) if (x < (int)xs.size()) in[x] = true; return find(in.begin(), in.end(), false) - in.begin(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto n = load<int>(); auto m = load<int>(); auto tax = loadMany<int>(n); auto dag = loadEdges(n, m); auto level = vector<int>(n, 0); auto topo = dag.toposort(); reverse(topo.begin(), topo.end()); for (auto v : topo) { auto near = vector<int>(); for (auto u : dag.edges[v]) near.push_back(level[u]); level[v] = mex(near); } auto xors = vector<int>(n, 0); for (auto v = 0; v < n; ++v) xors[level[v]] ^= tax[v]; auto t = lastIf(xors, [&](int z) { return z != 0; }); if (t != -1) { auto s = -1; for (auto v = 0; v < n; ++v) if (level[v] == t and (s == -1 or tax[s] < tax[v])) s = v; tax[s] ^= xors[t]; for (auto u : dag.edges[s]) tax[u] ^= xors[level[u]], xors[level[u]] = 0; cout << "WIN\n"; for (auto z : tax) cout << z << ' '; cout << '\n'; } else cout << "LOSE\n"; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int head[200005], ver[200005], nxt[200005], cnt; void add(int a, int b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; } vector<int> e[200005], has[200005]; int n, m, cd[200005]; long long a[200005], sg[200005]; int pos[200005], mex[200005], mx; bool vis[200005]; queue<int> q; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1, a, b; i <= m; i++) { scanf("%d%d", &a, &b); add(a, b), e[b].push_back(a), cd[a]++; } for (int i = 1; i <= n; i++) if (!cd[i]) q.push(i); while (!q.empty()) { int now = q.front(); q.pop(), cnt = 0; for (int i = head[now]; i; i = nxt[i]) mex[++cnt] = pos[ver[i]]; pos[now] = 1; sort(mex + 1, mex + 1 + cnt); for (int i = 1; i <= cnt; i++) if (mex[i] == pos[now]) pos[now]++; sg[pos[now]] ^= a[now]; has[pos[now]].push_back(now); mx = max(mx, pos[now]); for (int i = 0; i < e[now].size(); i++) { cd[e[now][i]]--; if (!cd[e[now][i]]) q.push(e[now][i]); } } for (int o = mx; o >= 1; o--) { if (sg[o] != 0) { int now; for (int i = 0; i < has[o].size(); i++) if (a[has[o][i]] ^ sg[o] <= a[has[o][i]]) { now = has[o][i]; break; } a[now] ^= sg[o]; for (int i = head[now]; i; i = nxt[i]) { int to = ver[i]; if (vis[pos[to]]) continue; vis[pos[to]]; a[to] = sg[pos[to]] ^ a[to]; } printf("WIN\n"); for (int i = 1; i <= n; i++) printf("%lld ", a[i]); return 0; } } cout << endl; printf("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e5 + 5; int n, m; long long h[N]; long long ans[N]; struct Edge { int num; int next; } edge[M]; int tot, last[N]; int du[N]; int sg[N]; bool used[N]; queue<int> L; int node[N], cnt; int mem[N]; void Add(int i, int j) { tot++; edge[tot].num = j; edge[tot].next = last[i]; last[i] = tot; } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); Add(u, v); du[v]++; } for (int i = 1; i <= n; i++) if (du[i] == 0) { L.push(i); node[++cnt] = i; } while (!L.empty()) { int u = L.front(); L.pop(); for (int k = last[u]; k != 0; k = edge[k].next) { int v = edge[k].num; du[v]--; if (du[v] == 0) { L.push(v); node[++cnt] = v; } } } for (int i = n; i >= 1; i--) { int u = node[i]; for (int k = last[u]; k != 0; k = edge[k].next) { int v = edge[k].num; mem[sg[v]] = i; } while (mem[sg[u]] == i) ++sg[u]; } for (int i = 1; i <= n; i++) ans[sg[i]] ^= h[i]; for (int i = n; i >= 0; i--) { if (ans[i] != 0) { printf("WIN\n"); for (int j = 1; j <= n; j++) { if (sg[j] != i) continue; if ((h[j] ^ ans[i]) >= h[j]) continue; h[j] = h[j] ^ ans[i]; for (int k = last[j]; k != 0; k = edge[k].next) { int v = edge[k].num; h[v] ^= ans[sg[v]]; ans[sg[v]] = 0; } } for (int j = 1; j <= n; j++) printf("%lld ", h[j]); return 0; } } printf("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; int n, m, h[maxn + 3], xo[maxn + 3], deg[maxn + 3], sg[maxn + 3], vis[maxn + 3], res[maxn + 3]; vector<int> G[maxn + 3], H[maxn + 3]; int main() { scanf("%d %d", &n, &m); for (int i = (1); i <= int(n); i++) scanf("%d", &h[i]); for (int i = (1); i <= int(m); i++) { int u, v; scanf("%d %d", &u, &v); G[u].push_back(v), H[v].push_back(u); } for (int i = (1); i <= int(n); i++) deg[i] = G[i].size(); queue<int> Q; for (int i = (1); i <= int(n); i++) if (!deg[i]) Q.push(i); for (int k = (1); k <= int(n); k++) { int u = Q.front(); Q.pop(); for (int i = (0); i <= int(G[u].size() - 1); i++) { int v = G[u][i]; vis[sg[v]] = k; } for (int i = (0); i <= int(n); i++) if (vis[i] != k) { sg[u] = i; break; } xo[sg[u]] ^= h[u]; for (int i = (0); i <= int(H[u].size() - 1); i++) { int v = H[u][i]; if (!--deg[v]) { Q.push(v); } } } bool flag = true; for (int i = (0); i <= int(n - 1); i++) flag &= xo[i] == 0; if (flag) { puts("LOSE"); } else { puts("WIN"); for (int i = (1); i <= int(n); i++) res[i] = h[i]; int x = -1; for (int i = (n - 1); i >= int(0); i--) if (xo[i]) { x = i; break; } for (int i = (1); i <= int(n); i++) if (sg[i] == x && (h[i] ^ xo[x]) < h[i]) { res[i] ^= xo[x]; break; } for (int i = (1); i <= int(n); i++) if (sg[i] < x && xo[sg[i]]) { res[i] ^= xo[sg[i]], xo[sg[i]] = 0; } for (int i = (1); i <= int(n); i++) printf("%d%c", res[i], " \n"[i == n]); } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200500; vector<int> side[maxn]; int n, m, val[maxn]; long long h[maxn], x[maxn], mx; void dfs(int u) { if (val[u] != -1) return; bool vis[705] = {0}; for (int i = 0; i < side[u].size(); i++) { int v = side[u][i]; dfs(v); vis[val[v]] = 1; } for (int i = 0; i < 705; i++) { if (!vis[i]) { val[u] = i; break; } } x[val[u]] ^= h[u]; mx = max(val[u] * 1ll, mx); } int main() { memset(val, -1, sizeof(val)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), side[u].push_back(v); for (int i = 1; i <= n; i++) dfs(i); for (int i = mx; i >= 0; i--) { if (x[i]) { printf("WIN\n"); for (int j = 1; j <= n; j++) { if (val[j] == i && h[j] ^ x[i] < h[j]) { h[j] = h[j] ^ x[i]; x[i] = 0; for (int k = 0; k < side[j].size(); k++) { int v = side[j][k]; if (!x[val[v]]) continue; h[v] = h[v] ^ x[val[v]]; x[val[v]] = 0; } break; } } for (int j = 1; j <= n; j++) printf("%lld ", h[j]); return 0; } } printf("LOSE\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, m, h[N], lev[N], Xor[N], cnt[N], deg[N]; vector<int> nxt[N], rnxt[N], vec[N]; set<int> s; queue<int> q; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; rnxt[y].push_back(x); nxt[x].push_back(y); ++deg[x]; } for (int i = 1; i <= n; ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : nxt[u]) ++cnt[lev[v]]; while (cnt[lev[u]]) ++lev[u]; Xor[lev[u]] ^= h[u]; for (auto v : nxt[u]) --cnt[lev[v]]; for (auto v : rnxt[u]) if (!--deg[v]) q.push(v); } for (int i = n; ~i; --i) if (Xor[i]) { puts("WIN"); for (int u = 1; u <= n; ++u) if (lev[u] == i && h[u] > (h[u] ^ Xor[i])) { h[u] ^= Xor[i]; for (auto v : nxt[u]) if (Xor[lev[v]]) h[v] ^= Xor[lev[v]], Xor[lev[v]] = 0; } for (int j = 1; j <= n; ++j) cout << h[j] << " "; puts(""); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize ("-ffloat-store") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define fi first #define se second #define mp make_pair #define pb push_back #define pop_b pop_back #define pf push_front #define pop_f pop_front #define mt make_tuple #define eb emplace_back typedef int64_t ll; #define int int64_t #define LB(x,v) (ll)(lower_bound(x.begin(),x.end(),v)-x.begin()) #define UB(x,v) (ll)(upper_bound(x.begin(),x.end(),v)-x.begin()) #define len(x) (ll)x.length() #define sz(x) (ll)x.size() typedef pair<ll,ll> ii; typedef long double ld; typedef vector<int> vi; typedef vector<set<ll>> vset; typedef vector<ll> vl; typedef vector<ld> vd; typedef unsigned long long ull; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i));} sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";} sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";} #else sim dor(const c&) { ris; } #endif }; vector<char*> tokenizer(const char* args) { char *token = new char[111]; strcpy(token, args); token = strtok(token, ", "); vector<char*> v({token}); while(token = strtok(NULL,", ")) v.push_back(token); return reverse(v.begin(), v.end()), v; } void debugg(vector<char*> args) { cerr << "\b\b "; } template <typename Head, typename... Tail> void debugg(vector<char*> args, Head H, Tail... T) { debug() << " [" << args.back() << ": " << H << "] "; args.pop_back(); debugg(args, T...); } #define harg(...) #__VA_ARGS__ #ifdef LOCAL #define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;} #else #define dbg(...) { } #endif #define rep(i, n) for (ll i = 0; i < (n); i++) #define Rep(i, n) for (ll i = 1; i <= (n); i++) #define repr(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rep2(i, l, r) for (ll i = (l); i < (r); i++) #define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--) #define all(a) a.begin(), a.end() #define cinai(a, n) vi a(n); rep(fukre, n) { cin>>a[fukre]; } #define cinal(a, n) vl a(n); rep(fukre, n) { cin>>a[fukre]; } #define coutai(a, n) rep(fukre, n) { cout<<a[fukre]<<" "; } ent; #define coutal(a, n) rep(fukre, n) { cout<<a[fukre]<<" "; } ent; #define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define ms(dp, x) memset(dp, x, sizeof(dp)) #define endl '\n' #define ent cout<<endl; ll powm(ll a, ll b, ll mod) { ll res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } const ld pi = 3.14159265358979323846; const ll mod = 1e9 + 7; const ll N = 1000005; const ll inf = 1e9; const ll INF = 1e18; void solve() { cout<<"WIN\n0 0 0 0\n"; } // #define testCases int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; #ifdef testCases cin>>tc; #endif for(int t = 1; t <= tc; t++) { #ifdef LOCAL int tt = clock(); #endif // cout<<"Case #"<<t<<": "; solve(); #ifdef LOCAL cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } return 0; } // watch
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 200010; int n, m; int a[N], deg[N], sg[N], ans[N]; vector<int> G[N], vec; inline void topo() { queue<int> q; for (int i = (1); i <= (n); ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int f = q.front(); q.pop(); vec.push_back(f); for (int i = (0); i < (G[f].size()); ++i) { deg[G[f][i]]--; if (!deg[G[f][i]]) q.push(G[f][i]); } } bool vis[N] = {0}; for (int i = (n - 1); i >= (0); --i) { for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 1; while (vis[sg[vec[i]]]) sg[vec[i]]++; for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 0; } } int main() { n = read(); m = read(); for (int i = (1); i <= (n); ++i) a[i] = read(); for (int i = (1); i <= (m); ++i) { int u = read(), v = read(); G[u].push_back(v); deg[v]++; } topo(); int maxx = -1, maxy = 0, id = -1; for (int i = (1); i <= (n); ++i) { if (maxx < sg[i] || maxx == sg[i] && maxy < a[i]) maxx = sg[i], maxy = a[i], id = i; ans[sg[i]] ^= a[i]; } int pd = 0; for (int i = (0); i <= (n); ++i) pd += ans[i]; if (!pd) return puts("LOSE"), 0; puts("WIN"); a[id] = ans[sg[id]] ^ a[id]; for (int i = (0); i < (G[id].size()); ++i) { if (ans[sg[G[id][i]]]) a[G[id][i]] ^= ans[sg[G[id][i]]]; } for (int i = (1); i <= (n); ++i) printf("%lld%c", a[i], i == n ? 10 : 32); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define ull unsigned long long #define ld long double #define pii pair <int, int> #define pll pair <ll, ll> #define pci pair <char, int> #define pld pair <ld, ld> #define ppld pair <pld, pld> #define ppll pair <pll, pll> #define pldl pair <ld, ll> #define vll vector <ll> #define vvll vector <vll> #define vpll vector <pll> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define mll map <ll, ll> #define fastmap gp_hash_table #define cd complex <double> #define vcd vector <cd> #define PI 3.14159265358979 #define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> #pragma 03 using namespace std; using namespace __gnu_pbds; ll n, m; vll adj[200005]; bool vis[200005]; ll h[200005]; ll pon[200005]; ll xrly[200005]; vll xnz; void dfs(ll u){ if (vis[u]) return; vis[u] = 1; set <ll> nmich; for (ll i = 0; i < adj[u].size(); i++){ dfs(adj[u][i]); nmich.insert(pon[adj[u][i]]); } ll mex = 0; while (nmich.count(mex)) mex++; pon[u] = mex; } int main(){ fastio; cin >> n >> m; for (ll i = 0; i < n; i++) cin >> h[i]; for (ll i = 0; i < m; i++){ ll u, v; cin >> u >> v; u--; v--; adj[u].pb(v); } for (ll i = 0; i < n; i++) dfs(i); for (ll i = 0; i < n; i++) xrly[pon[i]] ^= h[i]; for (ll i = 0; i < 200005; i++){ if (xrly[i]) xnz.pb(i); } if (xnz.empty()){ cout << "LOSE\n"; return 0; } cout << "WIN\n"; ll hi = xnz[xnz.size() - 1]; bool f = 0; for (ll i = 0; i < n; i++){ if (f) continue; if (pon[i] == hi){ if ((h[i] ^ xrly[hi]) < h[i]){ h[i] ^= xrly[hi]; for (ll j = 0; j < adj[i].size(); j++){ h[adj[i][j]] ^= xrly[pon[adj[i][j]]]; pon[adj[i][j]] = 0; } f = 1; } } } if (!f){ return -1; } for (ll i = 0; i < n; i++) cout << h[i] << " "; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; const long long N = 2e5 + 100; long long long long M[N]; vector<long long> g[N]; long long long long vis[N]; long long long long po = 1; long long long long h[N]; long long long long mex(long long long long v) { for (auto u : g[v]) { vis[M[u]] = po; } for (long long i = 0; i < N; i++) { if (vis[i] != po) return i; } po++; } long long long long t[N]; long long long long in[N]; int32_t main() { long long long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) cin >> h[i]; for (long long i = 0; i < m; i++) { long long long long u, v; cin >> u >> v; g[u].push_back(v); in[v]++; } vector<long long> ras; queue<long long> q; for (long long i = 1; i <= n; i++) { if (in[i] == 0) q.push(i); } while (q.size()) { long long long long v = q.front(); ras.push_back(v); q.pop(); for (auto u : g[v]) { in[u]--; if (in[u] == 0) q.push(u); } } reverse(ras.begin(), ras.end()); for (auto u : ras) { M[u] = mex(u); t[M[u]] ^= h[u]; } for (long long i = N - 1; i > -1; i--) { if (t[i]) { cout << "WIN" << '\n'; long long long long v = 0; for (long long j = 1; j <= n; j++) { if (M[j] == i) { long long long long z = t[M[j]] ^ h[j]; if (z < h[j]) { h[j] = z; v = j; break; } } } for (auto u : g[v]) { if (t[M[u]]) { t[M[u]] ^= h[u]; h[u] = t[M[u]]; t[M[u]] = 0; } } for (long long i = 1; i <= n; i++) { cout << h[i] << " "; } return 0; } } return cout << "LOSE" << '\n', 0; ; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int he[200010], ver[2 * 200010], nxt[2 * 200010], tot, in[200010]; void add(int x, int y) { ver[++tot] = y; nxt[tot] = he[x]; he[x] = tot; } int que[200010], cnt; long long w[200010]; vector<int> v[200010]; long long ans[200010]; int s[200010]; bool vis[200010]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", &w[i]); } for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); add(y, x); in[x]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (in[i] == 0) q.push(i); } while (!q.empty()) { int x = q.front(); q.pop(); que[++cnt] = x; for (int i = he[x]; i; i = nxt[i]) { in[ver[i]]--; if (!in[ver[i]]) q.push(ver[i]); } } int maxx = 0; for (int i = 1; i <= cnt; i++) { int x = que[i]; int stp = 0; if (!v[x].size()) ans[0] ^= w[x]; else { sort(v[x].begin(), v[x].end()); for (int j = 0, p = 0;; j++, p++) { if (v[x][p] != j) { stp = j; break; } while (v[x][p + 1] == j) p++; } ans[stp] ^= w[x]; maxx = max(maxx, stp); } s[x] = stp; for (int j = he[x]; j; j = nxt[j]) v[ver[j]].push_back(stp); } bool xx = false; for (int i = 0; i <= maxx; i++) { if (ans[i] != 0) { xx = true; break; } } if (xx) { puts("WIN"); for (int i = maxx; i >= 0; i--) { if (ans[i]) { maxx = i; break; } } int tmp = 0; for (int i = 1; i <= n; i++) { if (s[i] == maxx && ((w[i] ^ ans[s[i]]) < w[i])) { tmp = i; break; } } w[tmp] = ans[maxx] ^ w[tmp]; for (int i = 1; i <= n; i++) { if (i == tmp || s[i] >= s[tmp]) continue; for (int j = he[i]; j; j = nxt[j]) { if (ver[j] == tmp && vis[s[i]] == 0) { w[i] = ans[s[i]] ^ w[i]; vis[s[i]] = 1; break; } } } for (int i = 0; i < maxx; i++) { if (ans[i] && !vis[i]) { cout << "ass" << endl; return 0; } } for (int i = 1; i <= n; i++) printf("%lld ", w[i]); } else puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int read() { bool f = 1; int x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 0; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) - 48 + c; c = getchar(); } return f ? x : x * -1; } char cr[200]; int tt; inline void print(register int x, register char k = '\n') { if (!x) putchar('0'); if (x < 0) putchar('-'), x = -x; while (x) cr[++tt] = x % 10 + '0', x /= 10; while (tt) putchar(cr[tt--]); putchar(k); } const int maxn = 2e5 + 7; vector<int> e[maxn]; queue<int> q; int a[maxn], mex[maxn], nim[maxn], n, m; int vis[maxn], wh[maxn]; bool dfs(int u) { vis[u] = -1; for (int v : e[u]) { if (vis[v] == -1) return 0; if (vis[v] == 0) if (!dfs(v)) return 0; } vis[u] = 1; q.push(u); return 1; } signed main() { n = read(); m = read(); for (int i = 1; i <= n; i++) { a[i] = read(); } for (int i = 1; i <= m; i++) { int u = read(), v = read(); e[u].push_back(v); } for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(i); } for (int i = 1; i <= n; i++) { nim[mex[i]] ^= a[i]; } for (int i = 1; i < n; i++) { int u = q.front(); q.pop(); mex[u] = 1; for (int v : e[u]) wh[mex[v]] = 1; while (wh[mex[u]]) { mex[u]++; } nim[mex[u]] ^= a[u]; for (int v : e[u]) wh[mex[v]] = 0; cout << mex[u] << endl; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; cout << tmp << endl; break; } } if (!f) { puts("LOSS"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (mex[u] == tmp) { for (int v : e[u]) { a[v] = nim[mex[v]] ^ a[v]; } a[u] = nim[mex[u]] ^ a[u]; for (int i = 1; i <= n; i++) { print(a[i], ' '); } return 0; } } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 200010; int n, m; int a[N], deg[N], sg[N], ans[N]; vector<int> G[N], vec; inline void topo() { queue<int> q; for (int i = (1); i <= (n); ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int f = q.front(); q.pop(); vec.push_back(f); for (int i = (0); i < (G[f].size()); ++i) { deg[G[f][i]]--; if (!deg[G[f][i]]) q.push(G[f][i]); } } bool vis[N] = {0}; for (int i = (n - 1); i >= (0); --i) { for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 1; while (vis[sg[vec[i]]]) sg[vec[i]]++; for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 0; } } int main() { n = read(); m = read(); for (int i = (1); i <= (n); ++i) a[i] = read(); for (int i = (1); i <= (m); ++i) { int u = read(), v = read(); G[u].push_back(v); deg[v]++; } topo(); int maxx = -1, maxy = 0, id = -1; for (int i = (1); i <= (n); ++i) { if (maxx < sg[i] || maxx == sg[i] && maxy < a[i]) maxx = sg[i], maxy = a[i], id = i; ans[sg[i]] ^= a[i]; } int pd = 0; for (int i = (0); i <= (n); ++i) pd += ans[i]; if (!pd) return puts("LOSE"), 0; puts("WIN"); a[id] = ans[sg[id]] ^ a[id]; for (int i = (0); i < (G[id].size()); ++i) { if (ans[sg[G[id][i]]]) a[G[id][i]] ^= ans[sg[G[id][i]]]; } for (int i = (1); i <= (n); ++i) printf("%d%c", a[i], i == n ? 10 : 32); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; vector<int> adj[N], in[N], idx[N]; int mex[N], val[N], h[N], deg[N]; bool used[N]; queue<int> lis; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, i, j, k, l, max1; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> h[i]; } for (i = 1; i <= m; i++) { cin >> j >> k; adj[j].push_back(k); deg[j]++; in[k].push_back(j); } for (i = 1; i <= n; i++) { if (!deg[i]) { lis.push(i); } } while (lis.size()) { int x = lis.front(); lis.pop(); for (i = 0; i < adj[x].size(); i++) { used[mex[adj[x][i]]] = true; } for (i = 0; i < in[x].size(); i++) { deg[in[x][i]]--; if (!deg[in[x][i]]) { lis.push(in[x][i]); } } j = 0; while (used[j]) { j++; } idx[j].push_back(x); mex[x] = j; val[j] ^= h[x]; } for (i = n; i > -1; i--) { if (val[i] > 0) { max1 = i; break; } else { if (i == 0) { cout << "LOSE"; return 0; } } } cout << "WIN\n"; for (i = 0; i < idx[max1].size(); i++) { int x = idx[max1][i]; if (h[x] > (h[x] ^ val[max1])) { h[x] ^= val[max1]; val[max1] = 0; for (j = 0; j < adj[x].size(); j++) { if (val[mex[adj[x][j]]]) { h[adj[x][j]] ^= val[mex[adj[x][j]]]; val[mex[adj[x][j]]] = 0; } } break; } } for (i = 1; i <= n; i++) { cout << h[i] << ' '; } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma optimize("unroll-loops,no-stack-protector") using namespace std; namespace io { struct eof { eof() {} }; const int L = (1 << 21) | 5; char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55]; int f, qr; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; } inline void putc(char x) { *oS++ = x; if (oS == oT) flush(); } template <class I> inline void gi(I &x) { for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); (c < '0' || c > '9') && (c != EOF); c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) if (c == '-') f = -1; if (c == EOF) throw eof(); for (x = 0; c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) x = x * 10 + (c & 15); x *= f; } template <class I> inline void print(I x) { if (!x) putc('0'); if (x < 0) putc('-'), x = -x; while (x) qu[++qr] = x % 10 + '0', x /= 10; while (qr) putc(qu[qr--]); } inline void ps(const char *s) { int l = strlen(s), x; for (x = 0; x < l; x++) putc(s[x]); } struct IOC { ~IOC() { flush(); } } ioc; inline double readld() { double x = 0, y = 1; for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c < '0' || c > '9'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) if (c == '-') y = -1; assert(c != '.'); for (; c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) x = x * 10 + (c & 15); x *= y; assert(c != 'e'); if (c == '.') for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) y *= 0.1, x += y * (c & 15); return x; } inline void printld(double x, int y) { if (x < 0) putc('-'), x = -x; x += .5 * pow(.1, y); print((unsigned long long)x), putc('.'); for (x -= (unsigned long long)x; y; --y) x *= 10, putc((int)x + '0'), x -= (int)x; } } // namespace io using io::gi; using io::print; using io::putc; template <class T> int ctz(T a) { return sizeof(T) > 4 ? __builtin_ctzll(a) : __builtin_ctz(a); } template <class T> inline T gcd(T a, T b) { int shift = ctz(a | b); for (b >>= ctz(b), a >>= ctz(a); a; a -= b, a >>= ctz(a)) if (a < b) swap(a, b); return b << shift; } template <class T> void exgcd(T a, T b, T &x, T &y) { if (!b) return (void)(x = 1, y = 0); exgcd(b, a % b, y, x), y -= a / b * x; } template <class T> T Inv(T a, T p) { T x, y; exgcd(a, p, x, y); return (x % p + p) % p; } inline int fpow(int a, int t, int p) { static int r; for (r = 1; t; a = (long long)a * a % p, t >>= 1) if (t & 1) r = (long long)r * a % p; return r; } string to_string(string s) { return '"' + s + '"'; }; string to_string(const char *s) { return to_string(string(s)); } string to_string(bool f) { return f ? "true" : "false"; } template <class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <class T> string to_string(T v) { string s = "{", e = ""; for (auto &x : v) s += e + to_string(x), e = ", "; s += "}"; return s; } void debug_out() { cerr << endl; } template <class A, class... B> void debug_out(A x, B... y) { cerr << " " << to_string(x), debug_out(y...); } void scan() {} template <class A, class... B> void scan(A &a, B &...b) { gi(a), scan(b...); } template <class T> void read(T first, T last) { for (; first != last; ++first) gi(*first); } template <class T> void write(T first, T last) { for (; first != last; putc(++first == last ? '\n' : ' ')) print(*first); } template <class T> void show(T x) { print(x), putc('\n'); } template <class A, class... B> void show(A a, B... b) { print(a), putc(' '), show(b...); } template <class T> inline T abs(T x) { return x < 0 ? -x : x; } template <class T> bool chkmin(T &x, T y) { return y < x ? x = y, true : false; } template <class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } const int N = 2e5 + 5; int n, m, in[N], sg[N]; long long h[N], layer[N]; vector<int> adj[N]; bool vis[N]; int main() { int u, v; scan(n, m); read(h + 1, h + n + 1); queue<int> q; vector<int> topo; for (int i = 1; i <= m; ++i) scan(u, v), adj[u].emplace_back(v), in[v]++; for (int i = 1; i <= n; ++i) if (!in[i]) q.push(i); while (q.size()) { u = q.front(); topo.emplace_back(u); q.pop(); for (int v : adj[u]) if (!vis[v]) q.push(v), vis[v] = true; } reverse(topo.begin(), topo.end()); for (int x : topo) { set<int> nxt; for (int y : adj[x]) nxt.insert(sg[y]); while (nxt.count(sg[x])) ++sg[x]; layer[sg[x]] ^= h[x]; } for (u = n; u >= 0; --u) if (layer[u]) { puts("WIN"); for (v = 1; v <= n; ++v) if (sg[v] == u) break; h[v] ^= layer[u]; layer[u] = 0; for (int x : adj[v]) h[x] ^= layer[sg[x]], layer[sg[x]] = 0; write(h + 1, h + n + 1); exit(0); } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int NN = 200011; vector<int> adj[NN]; int n, m; int h[NN]; int xo[NN]; int g[NN]; int ans[NN]; int vst[NN]; int runs = 1; int calc(int u) { if (~g[u]) return g[u]; for (int v : adj[u]) calc(v); runs++; for (int v : adj[u]) vst[g[v]] = runs; for (int i = 0;; i++) if (vst[i] ^ runs) return g[u] = i; } int solve() { memset(g, -1, sizeof g); cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", h + i), ans[i] = h[i]; for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); } for (int i = 1; i <= n; i++) xo[calc(i)] ^= h[i]; int id = -1; for (int i = 0; i <= n; i++) if (xo[i]) id = i; if (id == -1) return puts("LOSE"); puts("WIN"); int now = -1; for (int i = 1; i <= n; i++) if (g[i] == id) { int u = xo[id] ^ h[i]; if (u < h[i]) { ans[i] = u; now = i; break; } } assert(now != -1); for (int u : adj[now]) ans[u] = xo[g[u]] ^ h[u]; for (int i = 1; i <= n; i++) printf("%d ", ans[i]); } int main() { solve(); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 7; int n, m, xor1, xor2; int a[MAXN]; int d[MAXN], dis[MAXN], type[MAXN]; vector<int> edge1[MAXN], edge2[MAXN]; queue<int> Q; int qf; void bfs() { for (int i = 1; i <= n; i++) if (d[i] == 0) Q.push(i), dis[i] = 1; while (Q.size()) { qf = Q.front(); Q.pop(); for (auto v : edge2[qf]) if (!dis[v]) Q.push(v), dis[v] = 1; } } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1, i2, i3; i <= m; i++) { cin >> i2 >> i3; edge1[i2].push_back(i3); edge2[i3].push_back(i2 + n); edge2[i3 + n].push_back(i2); d[i2]++; } bfs(); for (int i = 1; i <= n; i++) { if (dis[i]) xor1 ^= a[i], type[i] = 1; else if (dis[i + n]) xor2 ^= a[i], type[i] = 2; } if (xor1 == 0 && xor2 == 0) cout << "LOSE" << endl; else { cout << "WIN" << endl; if (xor2 != 0) { for (int i = 1; i <= n; i++) { if (type[i] == 2) { if (a[i] > (xor2 ^ a[i])) { a[i] = xor2 ^ a[i]; for (auto v : edge1[i]) { if (type[v] == 1) { a[v] = xor1 ^ a[v]; break; } } break; } } } } else { for (int i = 1; i <= n; i++) { if (type[i] == 1) { if (a[i] > (xor1 ^ a[i])) { a[i] = xor1 ^ a[i]; break; } } } } for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> inline long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } int h[200010], SG[200010], sum[200010], fst[200010]; int fir[200010], nxt[200010], dis[200010], id; inline void link(int a, int b) { nxt[++id] = fir[a], fir[a] = id, dis[id] = b; } int que[200010], hd = 1, tl = 1, in[200010]; int c[200010]; int main() { int n = gi(), m = gi(), a, b; for (int i = 1; i <= n; ++i) h[i] = gi(); while (m--) a = gi(), b = gi(), link(a, b), ++in[b]; for (int i = 1; i <= n; ++i) if (!in[i]) que[tl++] = i; while (hd ^ tl) { int x = que[hd++]; for (int i = fir[x]; i; i = nxt[i]) if (!--in[dis[i]]) que[tl++] = dis[i]; } for (int o = n, x; o; --o) { x = que[o]; for (int i = fir[x]; i; i = nxt[i]) ++c[SG[dis[i]]]; while (c[SG[x]]) ++SG[x]; sum[SG[x]] ^= h[x]; fst[SG[x]] = x; for (int i = fir[x]; i; i = nxt[i]) --c[SG[dis[i]]]; } for (int i = n, x; ~i; --i) if (sum[i]) { h[x = fst[i]] ^= sum[i]; for (int j = fir[x]; j; j = nxt[j]) h[dis[j]] ^= sum[SG[dis[j]]], sum[SG[dis[j]]] = 0; puts("WIN"); for (int j = 1; j <= n; ++j) printf("%d ", h[j]); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; int n, m; const int NN = 200011; int h[NN]; VI adj[NN]; map<int, int> g; int tot[NN]; inline int get(int u) { if (g.count(u)) return g[u]; map<int, int> vst; for (int v : adj[u]) { vst[get(v)] = 1; } for (int i = 0;; i++) if (vst.count(i) == 0) return g[u] = i; } int solve() { cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", h + i); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); } for (int i = 1; i <= n; i++) tot[get(i)] ^= h[i]; int id = n; while (tot[id] == 0) id--; if (tot[id] == 0) return puts("LOSE"); for (int i = 1; i <= n; i++) if (g[i] == id) { int u = tot[id] ^ h[i]; if (u < h[i]) { h[i] = u; for (int v : adj[i]) { h[v] ^= tot[g[v]]; tot[g[v]] = 0; } puts("WIN"); for (int i = 1; i <= n; i++) printf("%d ", h[i]); return 0; } } } int main() { solve(); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::memset; using std::min; using std::priority_queue; using std::vector; const int MAX_N = 79, MAX_BLK = 17; struct State { int loc, mask; State(int loc, int mask) : loc(loc), mask(mask) {} }; struct Info { State s; int d; Info(int d, int loc, int mask) : d(d), s(loc, mask) {} bool operator<(const Info &rhs) const { return d > rhs.d; } }; struct Table { int dis[MAX_N][1 << MAX_BLK]; int &operator[](const State &rhs) { return dis[rhs.loc][rhs.mask]; } Table() { memset(dis, -1, sizeof(dis)); } }; struct Edge { int v, c; Edge(int v, int c) : v(v), c(c) {} }; int N, M, K, A, B, belong[MAX_N], ans[MAX_N]; vector<Edge> edge[MAX_N]; namespace Init { struct RawEdge { int u, v, c; RawEdge(int u, int v, int c) : u(u), v(v), c(c) {} }; vector<RawEdge> rawEdge; int fa[MAX_N], siz[MAX_N], relabel[MAX_N]; int repr(int x) { return fa[x] == x ? x : fa[x] = repr(fa[x]); } void main() { cin >> N >> M >> A >> B; for (int i = 1; i <= N; i++) fa[i] = i, siz[i] = 1; for (int i = 1; i <= M; i++) { int u, v, c; cin >> u >> v >> c; rawEdge.emplace_back(u, v, c); if (c == A) { u = repr(u); v = repr(v); if (u != v) { fa[u] = v; siz[v] += siz[u]; } } } for (int i = 1; i <= N; i++) { int a = repr(i); if (siz[a] < 4) continue; if (!relabel[a]) relabel[a] = ++K; belong[i] = relabel[a]; } for (const auto &i : rawEdge) { if (i.c == B && repr(i.u) == repr(i.v)) continue; edge[i.u].emplace_back(i.v, i.c); edge[i.v].emplace_back(i.u, i.c); } } } // namespace Init void solve() { static priority_queue<Info> pq; static Table tab; pq.emplace(0, 1, 0); while (!pq.empty()) { auto curr = pq.top(); pq.pop(); int &d = tab[curr.s]; if (d != -1) continue; d = curr.d; for (const auto &i : edge[curr.s.loc]) { if (belong[i.v] && (curr.s.mask >> belong[i.v] - 1 & 1)) continue; Info t(curr); t.d += i.c; t.s.loc = i.v; if (belong[curr.s.loc] && belong[i.v] != belong[curr.s.loc]) t.s.mask |= 1 << belong[curr.s.loc] - 1; pq.push(t); } } for (int i = 1; i <= N; i++) ans[i] = INT_MAX; for (int i = 1; i <= N; i++) for (int j = 0; j < 1 << K; j++) if (tab.dis[i][j] != -1) ans[i] = min(ans[i], tab.dis[i][j]); } int main() { Init::main(); solve(); for (int i = 1; i <= N; i++) cout << ans[i] << " "; cout << endl; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; struct edge { int to, nxt; }; edge G[maxn]; int head[maxn], cnt; int h[maxn], deg[maxn]; queue<int> Q; int a[maxn]; bool vis[maxn]; int bel[maxn]; int nim[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", h + i); int u, v; while (m--) { scanf("%d %d", &u, &v); G[++cnt] = {v, head[u]}, head[u] = cnt; deg[v]++; } for (int i = 1; i <= n; i++) if (!deg[i]) Q.push(i); int c = 0; while (!Q.empty()) { u = Q.front(), Q.pop(); a[++c] = u; for (int i = head[u]; i; i = G[i].nxt) if (!(--deg[G[i].to])) Q.push(G[i].to); } int val = 0; for (int i = c; i; i--) { for (int j = head[a[i]]; j; j = G[j].nxt) vis[bel[G[j].to]] = true; while (vis[bel[a[i]]]) bel[a[i]]++; if (bel[a[i]] > val) val = bel[a[i]]; for (int j = head[a[i]]; j; j = G[j].nxt) vis[bel[G[j].to]] = false; } for (int i = 1; i <= n; i++) nim[bel[i]] ^= h[i]; int p = -1; for (int i = 0; i <= val; i++) if (nim[i]) p = i; if (p == -1) { printf("LOSE\n"); return 0; } for (int i = 1; i <= n; i++) if (bel[i] == p && (nim[p] ^ h[i]) > h[i]) { h[i] ^= nim[bel[i]]; for (int j = head[i]; j; j = G[j].nxt) if (!vis[bel[G[j].to]]) h[G[j].to] ^= nim[bel[G[j].to]], vis[bel[G[j].to]] = true; } printf("WIN\n"); for (int i = 1; i <= n; i++) printf("%d ", h[i]); printf("\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, a[200009], h[200009], q[200009], d[200009], s[200009], sg[200009], bo[200009]; vector<int> e[200009]; bool vis[200009]; int read() { int x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } long long readll() { long long x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } int dfs(int x) { if (vis[x]) return sg[x]; vis[x] = 1; for (int y : e[x]) sg[y] = dfs(y); for (int y : e[x]) bo[sg[y]] = x; for (sg[x] = 0; bo[sg[x]] == x; sg[x]++) ; s[sg[x]] ^= a[x]; return sg[x]; } int main() { scanf("%d%d", &n, &m); int i, x, y; for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); e[x].push_back(y); d[y]++; } for (i = 1; i <= n; i++) sg[i] = dfs(i); for (i = n; i; i--) if (s[i]) break; if (!i) { puts("LOSE"); return 0; } x = i; memset(vis, 0, sizeof(vis)); for (i = 1; i <= n; i++) if (sg[i] == x && (a[i] ^ s[x]) < a[i]) { a[i] ^= s[x]; for (int p : e[i]) { if (vis[sg[p]]) continue; vis[sg[p]] = 1; a[p] ^= s[sg[p]]; } break; } puts("WIN"); for (i = 1; i <= n; i++) printf("%d%c", a[i], i < n ? ' ' : '\n'); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long ver[N << 1], nxt[N << 1], head[N], deg[N], tot; long long h[N], st[N], vis[N << 1], id[N], t[N << 1], Max, top, n, m; queue<long long> q; inline long long read() { long long x = 0, ff = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * ff; } void add(long long x, long long y) { ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; deg[y]++; } signed main() { n = read(); m = read(); for (long long i = 1; i <= n; i++) h[i] = read(); for (long long i = 1; i <= m; i++) { long long u, v; u = read(); v = read(); add(u, v); } for (long long i = 1; i <= n; i++) if (!deg[i]) q.push(i); while (q.size()) { long long x = q.front(); q.pop(); st[++top] = x; for (long long i = head[x]; i; i = nxt[i]) { long long y = ver[i]; deg[y]--; if (!deg[y]) q.push(y); } } for (long long i = top; i >= 1; i--) { long long now = st[i]; for (long long j = head[now]; j; j = nxt[j]) vis[id[ver[j]]] = 1; for (long long nw = 0;; nw++) { if (!vis[nw]) { id[now] = nw; break; } } t[id[now]] ^= h[now]; Max = max(Max, id[now]); for (long long j = head[now]; j; j = nxt[j]) vis[id[ver[j]]] = 0; } long long maxx = -1; for (long long i = 0; i <= Max; i++) { if (t[i]) maxx = max(maxx, i); } if (maxx == -1) { puts("LOSE"); return 0; } for (long long i = 1; i <= n; i++) { if (!t[id[i]]) continue; if (id[i] == maxx && (t[id[i]] ^ h[i]) < h[i]) { h[i] ^= t[id[i]]; for (long long j = head[i]; j; j = nxt[j]) { long long y = ver[j]; if (t[id[y]]) { h[y] ^= t[id[y]]; } } break; } } puts("WIN"); for (long long i = 1; i <= n; i++) printf("%lld ", h[i]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 200010; int n, m; int a[N], deg[N], sg[N], ans[N]; vector<int> G[N], vec; inline void topo() { queue<int> q; for (int i = (1); i <= (n); ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int f = q.front(); q.pop(); vec.push_back(f); for (int i = (0); i < (G[f].size()); ++i) { deg[G[f][i]]--; if (!deg[G[f][i]]) q.push(G[f][i]); } } bool vis[N] = {0}; for (int i = (n - 1); i >= (0); --i) { for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 1; while (vis[sg[vec[i]]]) sg[vec[i]]++; for (int j = (0); j < (G[vec[i]].size()); ++j) vis[sg[G[vec[i]][j]]] = 0; } } int main() { n = read(); m = read(); for (int i = (1); i <= (n); ++i) a[i] = read(); for (int i = (1); i <= (m); ++i) { int u = read(), v = read(); G[u].push_back(v); deg[v]++; } topo(); int maxx = -1, maxy = 0, id = -1; for (int i = (1); i <= (n); ++i) { if (maxx < sg[i] || maxx == sg[i] && maxy < a[i]) maxx = sg[i], maxy = a[i], id = i; ans[sg[i]] ^= a[i]; } for (int i = (1); i <= (n); ++i) if (sg[i] == maxx && (ans[maxx] ^ a[i]) < a[i]) id = i; int pd = 0; for (int i = (0); i <= (n); ++i) pd += ans[i]; if (!pd) return puts("LOSE"), 0; puts("WIN"); a[id] = ans[sg[id]] ^ a[id]; for (int i = (0); i < (G[id].size()); ++i) { if (ans[sg[G[id][i]]]) a[G[id][i]] ^= ans[sg[G[id][i]]]; } for (int i = (1); i <= (n); ++i) printf("%d%c", a[i], i == n ? 10 : 32); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long double eps = 0.00000000001; int n, m; vector<int> E[300000]; int tab[300000]; int vis[300000]; int levelId[300000]; int levelXor[300000]; void dfs(int a) { vis[a] = true; vector<int> L; for (int v : E[a]) { if (!vis[v]) { dfs(v); L.push_back(levelId[v]); } } L.push_back(inf); sort(L.begin(), L.end()); L.resize(unique(L.begin(), L.end()) - L.begin()); int level = 0; while (level == L[level]) { level++; } levelId[a] = level; levelXor[level] ^= tab[a]; } void countMove(int level) { int high = 0; for (int i = 0; i <= 30; i++) { if (((1 << i) & levelXor[level]) != 0) { high = i; } } int a = -1; for (int i = 1; i <= n; i++) { if (levelId[i] == level) { if (((1 << high) & tab[i]) != 0) { a = i; } } } tab[a] ^= levelXor[level]; levelXor[level] = 0; for (int v : E[a]) { if (levelXor[levelId[v]] != 0) { tab[v] ^= levelXor[levelId[v]]; levelXor[levelId[v]] = 0; } } } void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> tab[i]; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; E[u].push_back(v); } for (int i = 1; i <= n; i++) { if (!vis[i]) { dfs(i); } } int level = -1; for (int i = 0; i <= n; i++) { if (levelXor[i] != 0) { level = i; } } if (level == -1) { cout << "LOSE" << "\n"; return; } countMove(level); cout << "WIN" << "\n"; for (int i = 1; i <= n; i++) { cout << tab[i] << " "; } cout << "\n"; } void clear() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int z = 1; for (int i = 0; i < z; i++) { solve(); clear(); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; struct edge { int to, nxt; }; edge G[maxn]; int head[maxn], cnt; int h[maxn], deg[maxn]; queue<int> Q; int a[maxn]; bool vis[maxn]; int bel[maxn]; int nim[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", h + i); int u, v; while (m--) { scanf("%d %d", &u, &v); G[++cnt] = {v, head[u]}, head[u] = cnt; deg[v]++; } for (int i = 1; i <= n; i++) if (!deg[i]) Q.push(i); int c = 0; while (!Q.empty()) { u = Q.front(), Q.pop(); a[c++] = u; for (int i = head[u]; i; i = G[i].nxt) if (!(--deg[G[i].to])) Q.push(G[i].to); } int val = 0; while (c--) { for (int i = head[a[c]]; i; i = G[i].nxt) vis[bel[G[i].to]] = true; while (vis[bel[a[c]]]) bel[a[c]]++; if (bel[a[c]] > val) val = bel[a[c]]; for (int i = head[a[c]]; i; i = G[i].nxt) vis[bel[G[i].to]] = false; } for (int i = 1; i <= n; i++) nim[bel[i]] ^= h[i]; int p = -1; for (int i = val; i >= 0; i--) if (nim[i]) { p = i; break; } if (p == -1) { printf("LOSE\n"); return 0; } for (int i = 1; i <= n; i++) if (bel[i] == p && (nim[bel[i]] ^ h[i]) <= h[i]) { h[i] ^= nim[bel[i]], vis[bel[i]] = true; for (int j = head[i]; j; j = G[j].nxt) if (!vis[bel[G[j].to]]) h[G[j].to] ^= nim[bel[G[j].to]], vis[bel[G[j].to]] = true; } printf("WIN\n"); for (int i = 1; i <= n; i++) printf("%d ", h[i]); printf("\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << "<" << x.first << ", " << x.second << ">"; } template <class n> auto operator<<(ostream &p, n y) -> typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type { int o = 0; p << "{"; for (auto c : y) { if (o++) p << ", "; p << c; } return p << "}"; } void dor() { cerr << endl; } template <class n, class... second> void dor(n p, second... y) { cerr << p << " "; dor(y...); } template <class n, class second> void mini(n &p, second y) { if (p > y) p = y; } template <class n, class second> void maxi(n &p, second y) { if (p < y) p = y; } const int M = 1024 * 256; int H[M], mex[M]; int n, m, out[M], xo[M]; vector<int> V[M], T[M]; int main() { scanf("%d%d", &n, &m); for (int i = (1); i <= (int)(n); ++i) { scanf("%d", H + i); } for (int i = (1); i <= (int)(m); ++i) { int a, b; scanf("%d%d", &a, &b); V[a].push_back(b); T[b].push_back(a); out[a]++; } queue<int> Q; for (int i = (1); i <= (int)(n); ++i) { if (out[i] == 0) { Q.push(i); } } while (!Q.empty()) { int v = Q.front(); Q.pop(); vector<int> X; for (auto x : V[v]) { X.push_back(mex[x]); } sort((X).begin(), (X).end()); X.push_back(1e9); for (int i = (0); i <= (int)((int)(X).size() - 1); ++i) { if (X[i] != i) { mex[v] = i; break; } } for (auto x : T[v]) { out[x]--; if (out[x] == 0) { Q.push(x); } } xo[mex[v]] ^= H[v]; } int t = -1; for (int i = (0); i <= (int)(n); ++i) { if (xo[i] != 0) { t = i; } } if (t == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (int i = (1); i <= (int)(n); ++i) { if (mex[i] != t || (xo[t] ^ H[i]) >= H[i]) { continue; } H[i] = xo[t] ^ H[i]; for (auto x : V[i]) { if (xo[mex[x]] != 0) { H[x] = xo[mex[x]] ^ H[x]; xo[mex[x]] = 0; } } break; } for (int i = (1); i <= (int)(n); ++i) { printf("%d ", H[i]); } printf("\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> namespace io { int F() { int F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } long long G() { long long F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } } // namespace io int q[222222], hq, tq; int deg[222222]; struct edge { int to; int next; } e[555555]; int pe = 222222; void insert(int a, int to) { e[pe] = (edge){to, e[a].next}; e[a].next = pe++; deg[to]++; } int h[222222]; int f[222222]; int g[222222]; int vis[222222]; int mark[222222]; int res[222222]; int boom[222222]; int main() { int n = io::F(), m = io::F(); for (int i = 1; i <= n; ++i) h[i] = io::F(); for (int i = 1; i <= m; ++i) { int x = io::F(), y = io::F(); insert(x, y); } for (int i = 1; i <= n; ++i) if (deg[i] == 0) q[tq++] = i; for (; hq != tq; ++hq) for (int p = e[q[hq]].next; p; p = e[p].next) if (--deg[e[p].to] == 0) q[tq++] = e[p].to; for (int i = tq - 1; i >= 0; --i) { for (int p = e[q[i]].next; p; p = e[p].next) vis[f[e[p].to]] = i + 1; while (vis[f[q[i]]] == i + 1) ++f[q[i]]; } for (int i = 1; i <= n; ++i) g[f[i]] ^= h[i]; int fl = 0; for (int i = 0; i <= n; ++i) fl |= g[i]; if (fl == 0) puts("LOSE"), exit(0); puts("WIN"); int mn, pl, mf = 0; for (int i = 0; i <= n; ++i) if (g[f[i]]) (mf < (f[i]) ? mf = (f[i]), 1 : 0); mn = 1 << 31 - __builtin_clz(g[mf]); for (int i = 1; i <= n; ++i) if (f[i] == mf && h[i] & mn) pl = i; mark[pl] = 1; for (int p = e[pl].next; p; p = e[p].next) mark[e[p].to] = 1; for (int i = 1; i <= n; ++i) if (!mark[i]) res[f[i]] ^= h[i]; h[pl] = res[mf]; for (int p = e[pl].next; p; p = e[p].next) if (!boom[f[e[p].to]]) boom[f[e[p].to]] = 1, h[e[p].to] = res[f[e[p].to]]; for (int i = 1; i <= n; ++i) printf("%d%c", h[i], " \n"[i == n]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const int N = 2e5 + 5; long long h[N], s[N]; int w[N]; vector<int> g[N]; bool used[N]; void dfs(int node) { if (used[node]) return; used[node] = 1; vector<int> t; for (int to : g[node]) { dfs(to); t.push_back(w[to]); } sort(t.begin(), t.end()); t.erase(unique(t.begin(), t.end()), t.end()); while (w[node] < t.size() && t[w[node]] == w[node]) w[node]++; s[w[node]] ^= h[node]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; g[a].push_back(b); } for (int i = 0; i < n; i++) { dfs(i); } bool win = false; int mx = -1; for (int i = 0; i < n; i++) { if (s[i] != 0) { win = true; if (mx == -1 || w[mx] < w[i] || w[mx] == w[i] && s[mx] < s[i]) mx = i; } } if (win) { cout << "WIN\n"; for (int to : g[mx]) { if (s[w[to]] != 0) { s[w[to]] ^= h[to]; h[to] = s[w[to]]; s[w[to]] = 0; } } s[w[mx]] ^= h[mx]; h[mx] = s[w[mx]]; for (int i = 0; i < n; i++) cout << h[i] << " "; } else { cout << "LOSE"; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int h[200000]; vector<int> adjList[200000]; int nim[200000]; int doDFS(int u) { if (nim[u] != -1) return 0; int i, j = 0; vector<int> s; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; doDFS(v), s.push_back(nim[v]); } sort(s.begin(), s.end()); for (i = 0; i <= adjList[u].size(); i++) { while ((j < s.size()) && (s[j] < i)) j++; if ((j == s.size()) || (s[j] > i)) break; } nim[u] = i; return 0; } int x[200000], y[200000]; int main() { int i; int n, m, u, v; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &h[i]); for (i = 0; i < m; i++) { scanf("%d %d", &u, &v); adjList[u - 1].push_back(v - 1); } int c = 0; fill(nim, nim + n, -1); for (i = 0; i < n; i++) { doDFS(i); x[nim[i]] ^= h[i]; } for (i = 0; i < n; i++) { if (x[i] > 0) c++; } if (c == 0) { printf("LOSE\n"); return 0; } int j; for (i = 0; i < n; i++) { if ((x[nim[i]] ^ h[i]) < h[i]) { int c2 = 1; for (j = 0; j < adjList[i].size(); j++) { int v = adjList[i][j]; if ((x[nim[v]] > 0) && !y[nim[v]]) c2++; y[nim[v]] = 1; } if (c == c2) { h[i] ^= x[nim[i]]; for (j = 0; j < adjList[i].size(); j++) { int v = adjList[i][j]; h[v] ^= x[nim[v]], x[nim[v]] = 0; } printf("WIN\n"); for (j = 0; j < n; j++) printf("%d%c", h[j], (j == (n - 1)) ? '\n' : ' '); break; } else { for (j = 0; j < adjList[i].size(); j++) y[adjList[i][j]] = 0; } } } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int MAXN = 200010; int head[MAXN], nxt[MAXN], to[MAXN], ind[MAXN], tot; void adde(int b, int e) { nxt[++tot] = head[b]; to[head[b] = tot] = e; ++ind[e]; } int A[MAXN], mx[MAXN]; std::set<int> S; int n, m; std::queue<int> q; int bfn[MAXN], idx; int B[MAXN]; int main() { std::ios_base::sync_with_stdio(false), std::cin.tie(0); std::cin >> n >> m; for (int i = 1; i <= n; ++i) std::cin >> A[i]; for (int i = 1, b, e; i <= m; ++i) std::cin >> b >> e, adde(b, e); for (int i = 1; i <= n; ++i) if (!ind[i]) q.push(i); while (!q.empty()) { int t = q.front(); q.pop(); bfn[++idx] = t; for (int i = head[t]; i; i = nxt[i]) if (!--ind[to[i]]) q.push(to[i]); } for (int T = idx; T; --T) { const int u = bfn[T]; for (int i = head[u]; i; i = nxt[i]) S.insert(mx[to[i]]); while (S.count(mx[u])) ++mx[u]; S.clear(); B[mx[u]] ^= A[u]; } int cur = n; while (cur && !B[cur]) --cur; if (!cur) return std::cout << "LOSE" << std::endl, 0; for (int u = 1; u <= n; ++u) if (mx[u] == cur) { if ((A[u] ^ B[cur]) > A[u]) continue; A[u] ^= B[cur], B[cur] = 0; for (int i = head[u]; i; i = nxt[i]) A[to[i]] ^= B[mx[to[i]]], mx[to[i]] = 0; break; } std::cout << "WIN" << std::endl; for (int i = 1; i <= n; ++i) std::cout << A[i] << ' '; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include<bits/stdc++.h> #define Rint register int using namespace std; const int N = 200003; template<typename T> inline void read(T &x){ int ch = getchar(); x = 0; for(;ch < '0' || ch > '9';ch = getchar()); for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0'; } int n, m, h[N], sg[N], head[N], to[N], nxt[N], ans[N]; bool vis[N]; inline void add(int a, int b){ static int cnt = 0; to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt; } inline void dfs(int x){ for(Rint i = head[x];i;i = nxt[i]) if(sg[to[i]] == -1) dfs(to[i]); for(Rint i = head[x];i;i = nxt[i]) vis[sg[to[i]]] = true; for(;vis[sg[x]];++ sg[x]); for(Rint i = head[x];i;i = nxt[i]) vis[sg[to[i]]] = false; } int main(){ read(n); read(m); for(Rint i = 1;i <= n;++ i) read(h[i]); for(Rint i = 1, u, v;i <= m;++ i) read(u), read(v), add(u, v); memset(sg, -1, sizeof sg); for(Rint i = 1;i <= n;++ i){ if(sg[i] == -1) dfs(i); ans[sg[i]] ^= h[i]; } for(Rint i = n - 1;~i;-- i) if(ans[i]){ puts("WIN"); for(Rint j = 1;j <= n;++ j) if(sg[j] == i && (h[j] ^ ans[i]) < h[j]){ h[j] ^= ans[i]; for(Rint k = head[j];k;k = nxt[k]) h[to[k]] ^= ans[sg[to[k]]], ans[sg[to[k]]] = 0; for(Rint k = 1;k <= n;++ k) printf("%d ", h[k]); return 0; } } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long h[200005], s[200005]; int n, m, a, b, ru[200006], mex[200005], fu[200005], ma; vector<int> x[200005]; int dfs(int now) { for (int i = 0; i < x[now].size(); i++) dfs(x[now][i]); for (int i = 0; i < x[now].size(); i++) fu[mex[x[now][i]]] = now; for (int i = 0; i <= n; i++) if (fu[i] != now) return mex[now] = i; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", h + i); for (int j = 1; j <= m; j++) { scanf("%d%d", &a, &b); x[a].push_back(b); ru[b]++; } for (int i = 1; i <= n; i++) if (ru[i] == 0) dfs(i); for (int i = 1; i <= n; i++) s[mex[i]] ^= h[i]; int ans = 0; ma = -1; memset(fu, 0, sizeof(fu)); for (int i = 1; i <= n; i++) if (s[mex[i]] != 0) fu[mex[i]] = 1, ma = max(ma, mex[i]); if (~ma) { puts("WIN"); for (int i = 1; i <= n; i++) { if (mex[i] == ma) { h[i] ^= s[mex[i]]; for (int j = 0; j < x[i].size(); j++) if (fu[mex[x[i][j]]]) h[x[i][j]] ^= s[mex[x[i][j]]], fu[mex[x[i][j]]] = 0; for (int i = 1; i <= n; i++) printf("%lld ", h[i]); return 0; } } } else puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } int n, m, val[maxn], Id[maxn], sum[maxn], vis[maxn]; vector<int> to[maxn]; int dfs(int u) { if (vis[u]) return Id[u]; vector<int> t; vis[u] = 1; for (int v : to[u]) t.push_back(dfs(v)); sort(t.begin(), t.end()); for (int lst = 0, i = 0; i < t.size(); ++i) if (t[i] > lst + 1) { Id[u] = lst + 1; break; } else lst = t[i]; return Id[u]; } int main() { n = gi(); m = gi(); for (int i = 1; i <= n; ++i) val[i] = gi(); for (int i = 1; i <= m; ++i) to[gi()].push_back(gi()); for (int i = 1; i <= n; ++i) if (vis[i]) dfs(i); for (int i = 1; i <= n; ++i) sum[Id[i]] ^= val[i]; int pos = -1; for (int i = 0; i <= n; ++i) if (sum[i]) pos = i; if (~pos) { puts("WIN"); for (int i = 1; i <= n; ++i) if (Id[i] == pos && (val[i] ^ sum[pos]) < val[i]) { val[i] = val[i] ^ sum[pos]; sum[pos] = 0; for (int v : to[i]) val[v] = sum[Id[v]] ^ val[v], sum[Id[v]] = 0; } for (int i = 1; i <= n; ++i) printf("%d ", val[i]); } else puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int head[200005], ver[200005], nxt[200005], cnt; void add(int a, int b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; } vector<int> e[200005], has[200005]; int n, m, cd[200005]; long long a[200005], sg[200005]; int pos[200005], mex[200005], mx; bool vis[200005]; queue<int> q; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1, a, b; i <= m; i++) { scanf("%d%d", &a, &b); add(a, b), e[b].push_back(a), cd[a]++; } for (int i = 1; i <= n; i++) if (!cd[i]) q.push(i); while (!q.empty()) { int now = q.front(); q.pop(), cnt = 0; for (int i = head[now]; i; i = nxt[i]) mex[++cnt] = pos[ver[i]]; pos[now] = 1; sort(mex + 1, mex + 1 + cnt); for (int i = 1; i <= cnt; i++) if (mex[i] == pos[now]) pos[now]++; sg[pos[now]] ^= a[now]; has[pos[now]].push_back(now); mx = max(mx, pos[now]); for (int i = 0; i < e[now].size(); i++) { cd[e[now][i]]--; if (!cd[e[now][i]]) q.push(e[now][i]); } } for (int o = mx; o >= 1; o--) { if (sg[o] != 0) { int now; for (int i = 0; i < has[o].size(); i++) if ((a[has[o][i]] ^ sg[o]) <= a[has[o][i]]) { now = has[o][i]; break; } a[now] ^= sg[o]; for (int i = head[now]; i; i = nxt[i]) { int to = ver[i]; if (vis[pos[to]]) continue; vis[pos[to]]; a[to] = sg[pos[to]] ^ a[to]; } printf("WIN\n"); for (int i = 1; i <= n; i++) printf("%lld ", a[i]); return 0; } } printf("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int N = 200005; int n, m, cnt, last[N], a[N], deg[N], sg[N], h[N], sum[N]; bool vis[N]; struct edge { int to, next; } e[N]; void addedge(int u, int v) { e[++cnt].to = v; e[cnt].next = last[u]; last[u] = cnt; } void get_sg() { int tot = 0; for (int i = 1; i <= n; i++) if (!deg[i]) a[++tot] = i; for (int i = 1; i <= n; i++) { int x = a[i]; for (int j = last[x]; j; j = e[j].next) { deg[e[j].to]--; if (!deg[e[j].to]) a[++tot] = e[j].to; } } for (int i = n; i >= 1; i--) { int x = a[i]; for (int j = last[x]; j; j = e[j].next) vis[sg[e[j].to]] = 1; for (; vis[sg[x]]; sg[x]++) ; for (int j = last[x]; j; j = e[j].next) vis[sg[e[j].to]] = 0; } } int get_high(int x) { if (!x) return -1; for (int i = 30; i >= 0; i--) if (x & (1 << i)) return i; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); addedge(u, v); deg[v]++; } get_sg(); for (int i = 1; i <= n; i++) sum[sg[i]] ^= h[i]; int mx = -1; for (int i = n; i >= 0; i--) if (sum[i]) { mx = i; break; } if (mx == -1) { puts("LOSE"); return 0; } int pos = 0; for (int i = 1; i <= n; i++) if (sg[i] == mx && h[i] ^ sum[mx] < h[i]) { pos = i; break; } puts("WIN"); h[pos] = sum[mx] ^ h[pos]; for (int i = last[pos]; i; i = e[i].next) { int x = e[i].to; if (vis[sg[x]]) continue; vis[sg[x]] = 1; h[x] = sum[sg[x]] ^ h[x]; } for (int i = 1; i <= n; i++) printf("%d ", h[i]); puts(""); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long fz[5000010], d[5000010], h[5000010]; vector<int> g[5000010]; void dfs(int u) { if (d[u]) return; d[u] = 1; vector<int> px; px.clear(); for (auto v : g[u]) { dfs(v); px.push_back(d[v]); } for (auto x : px) { if (x != d[u]) break; d[u]++; } } void df2(int u, int z) { h[u] ^= fz[z]; for (auto v : g[u]) if (d[v] == z - 1) { df2(v, z - 1); return; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= m; i++) { cin >> a >> b; g[a].push_back(b); } for (int i = 1; i <= n; i++) if (!d[i]) dfs(i); for (int i = 1; i <= n; i++) fz[d[i]] ^= h[i]; for (int i = n; i >= 1; i--) { if (fz[i]) { cout << "WIN" << endl; for (int j = 1; j <= n; j++) if (d[j] == i && ((h[j] ^ fz[i]) < h[j])) { df2(j, i); break; } for (int j = 1; j <= n; j++) cout << h[j] << ' '; cout << endl; return 0; } } cout << "LOSE" << endl; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool chkmin(T &x, T y) { return y < x ? (x = y, true) : false; } template <class T> bool chkmax(T &x, T y) { return y > x ? (x = y, true) : false; } struct __init { __init() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(16); cout << fixed; srand(time(0) ^ unsigned(unsigned long long(new char))); } } static __init__; const int maxn = 2e5 + 10; int n, m; int a[maxn]; vector<int> h[maxn]; bool vis[maxn]; int id[maxn], tot; void dfs(int x) { vis[x] = true; for (int v : h[x]) if (!vis[v]) dfs(v); id[++tot] = x; } int sg[maxn]; int xum[maxn]; void no() { cout << "LOSE\n"; exit(0); } int main() { cin >> n >> m; for (int i = 1; i <= (n); i++) cin >> a[i]; int u, v; for (int i = 1; i <= (m); i++) { cin >> u >> v; h[u].push_back(v); } for (int i = 1; i <= (n); i++) if (!vis[i]) dfs(i); for (int i = 1; i <= (n); i++) { int x = id[i]; memset(vis, 0, sizeof(bool) * (h[x].size() + 5)); for (int v : h[x]) vis[sg[v]] = true; for (int j = 0; j <= (n); j++) if (!vis[j]) { sg[x] = j; break; } } for (int i = 1; i <= (n); i++) xum[sg[i]] ^= a[i]; int Max = -1; for (int i = n; i >= (1); i--) if (xum[i]) { Max = i; break; } if (Max == -1) no(); memset(vis, 0, sizeof vis); for (int i = 1; i <= (n); i++) if (sg[i] == Max && a[i] ^ xum[Max] < a[i]) { a[i] ^= xum[Max]; for (int v : h[i]) if (sg[v] < Max && !vis[sg[v]]) { a[v] ^= xum[sg[v]]; vis[sg[v]] = true; } break; } cout << "WIN\n"; for (int i = 1; i <= (n); i++) cout << a[i] << ' '; cout << '\n'; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize ("-ffloat-store") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define fi first #define se second #define mp make_pair #define pb push_back #define pop_b pop_back #define pf push_front #define pop_f pop_front #define mt make_tuple #define eb emplace_back typedef int64_t ll; #define int int64_t #define LB(x,v) (ll)(lower_bound(x.begin(),x.end(),v)-x.begin()) #define UB(x,v) (ll)(upper_bound(x.begin(),x.end(),v)-x.begin()) #define len(x) (ll)x.length() #define sz(x) (ll)x.size() typedef pair<ll,ll> ii; typedef long double ld; typedef vector<int> vi; typedef vector<set<ll>> vset; typedef vector<ll> vl; typedef vector<ld> vd; typedef unsigned long long ull; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i));} sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";} sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";} #else sim dor(const c&) { ris; } #endif }; vector<char*> tokenizer(const char* args) { char *token = new char[111]; strcpy(token, args); token = strtok(token, ", "); vector<char*> v({token}); while(token = strtok(NULL,", ")) v.push_back(token); return reverse(v.begin(), v.end()), v; } void debugg(vector<char*> args) { cerr << "\b\b "; } template <typename Head, typename... Tail> void debugg(vector<char*> args, Head H, Tail... T) { debug() << " [" << args.back() << ": " << H << "] "; args.pop_back(); debugg(args, T...); } #define harg(...) #__VA_ARGS__ #ifdef LOCAL #define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;} #else #define dbg(...) { } #endif #define rep(i, n) for (ll i = 0; i < (n); i++) #define Rep(i, n) for (ll i = 1; i <= (n); i++) #define repr(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rep2(i, l, r) for (ll i = (l); i < (r); i++) #define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--) #define all(a) a.begin(), a.end() #define cinai(a, n) vi a(n); rep(fukre, n) { cin>>a[fukre]; } #define cinal(a, n) vl a(n); rep(fukre, n) { cin>>a[fukre]; } #define coutai(a, n) rep(fukre, n) { cout<<a[fukre]<<" "; } ent; #define coutal(a, n) rep(fukre, n) { cout<<a[fukre]<<" "; } ent; #define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define ms(dp, x) memset(dp, x, sizeof(dp)) #define endl '\n' #define ent cout<<endl; ll powm(ll a, ll b, ll mod) { ll res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } const ld pi = 3.14159265358979323846; const ll mod = 1e9 + 7; const ll N = 200005; const ll inf = 1e9; const ll INF = 1e18; int vis[N]; int n, m; int H[N], fwd_deg[N], grundy[N], grundy2[N]; vi fwd[N], rev[N]; void solve() { cin>>n>>m; rep(i, n) cin>>H[i]; rep(i, m){ int u, v; cin>>u>>v; u--, v--; fwd[u].pb(v); rev[v].pb(u); fwd_deg[u]++; } deque<int> q; rep(i, n) if(!fwd_deg[i]) q.pb(i); while(sz(q)){ int cur = q.front(); vis[cur] = 1; q.pop_front(); set<int> pres; for(int i : rev[cur]){ fwd_deg[i]--; if(!fwd_deg[i]){ q.pb(i); } } for(int i : fwd[cur]){ if(vis[i]) pres.insert(grundy[i]); } pres.insert(inf); while(*pres.begin() == grundy[cur]){ grundy[cur]++; pres.erase(pres.begin()); } dbg(cur, grundy[cur], grundy2[grundy[cur]]); grundy2[grundy[cur]] ^= H[cur]; } int lose = 1, hi = -1; rep(i, n + 1){ if(grundy2[grundy[i]]){ hi = max(hi, grundy[i]); lose = 0; } } if(lose){ cout<<"LOSE\n"; return; } cout<<"WIN\n"; for(int i = 0; i < n; i++){ if(grundy[i] == hi){ if((H[i] ^ grundy2[grundy[i]]) <= H[i]){ H[i] ^= grundy2[grundy[i]]; grundy2[grundy[i]] = 0; } }else{ dbg("hi"); H[i] ^= grundy2[grundy[i]]; grundy2[grundy[i]] = 0; } cout<<H[i]<<" "; } cout<<endl; } // #define testCases int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; #ifdef testCases cin>>tc; #endif for(int t = 1; t <= tc; t++) { #ifdef LOCAL int tt = clock(); #endif // cout<<"Case #"<<t<<": "; solve(); #ifdef LOCAL cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } return 0; } // watch
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; int const nmax = 200000; int v[1 + nmax]; std::vector<int> g[1 + nmax]; int mex(std::vector<int> aux) { std::sort(aux.begin(), aux.end()); aux.erase(std::unique(aux.begin(), aux.end()), aux.end()); for (int i = 0; i < aux.size(); i++) if (aux[i] != i) return i; return aux.size(); } int color[1 + nmax], dp[1 + nmax]; void dfs(int node) { std::vector<int> aux; for (int h = 0; h < g[node].size(); h++) { int to = g[node][h]; if (color[to] == -1) dfs(to); aux.push_back(color[to]); } color[node] = mex(aux); } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; for (int i = 1; i <= n; i++) std::cin >> v[i]; for (int i = 1; i <= n; i++) color[i] = -1; for (int i = 1; i <= m; i++) { int x, y; std::cin >> x >> y; g[x].push_back(y); } for (int i = 1; i <= n; i++) if (color[i] == -1) dfs(i); for (int i = 1; i <= n; i++) dp[color[i]] ^= v[i]; int result = 0; for (int i = 0; i <= n; i++) result += (dp[i] != 0); if (result == 0) std::cout << "LOSE\n"; else { for (int i = n; 0 <= i; i--) if (dp[i] != 0) { std::cout << "WIN\n"; for (int j = 1; j <= n; j++) if (color[j] == i) { if (0 < dp[i] && (v[j] ^ dp[i]) < v[j]) { v[j] ^= dp[i]; dp[i] ^= dp[i]; for (int h = 0; h < g[i].size(); h++) { int to = g[i][h]; if (0 < dp[color[to]]) { v[to] ^= dp[color[to]]; dp[color[to]] = 0; } } break; } } for (int j = 1; j <= n; j++) std::cout << v[j] << " "; std::cout << '\n'; return 0; } } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 10; int n, m, clk; int h[maxN + 1], vis[maxN + 1]; int p[maxN + 1], sum[maxN + 1]; vector<int> G[maxN + 1]; inline int read() { int num = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar(); return num * f; } inline void dfs(int u) { if (p[u] != -1) return; for (int i = 0; i < G[u].size(); i++) dfs(G[u][i]); clk++; for (int i = 0; i < G[u].size(); i++) vis[p[G[u][i]]] = clk; p[u] = 0; while (vis[p[u]] == clk) p[u]++; sum[p[u]] ^= h[u]; } int main() { n = read(), m = read(); for (int i = 1; i <= n; i++) h[i] = read(); for (int i = 1; i <= m; i++) { int x = read(), y = read(); G[x].push_back(y); } fill(p + 1, p + n + 1, -1); for (int i = 1; i <= n; i++) dfs(i); int id = -1; for (int i = 1; i <= n; i++) if (sum[p[i]]) id = max(id, p[i]); if (id == -1) { puts("LOSE"); return 0; } puts("WIN"); int x; for (int i = 1; i <= n; i++) if (p[i] == id) { x = i; break; } h[x] ^= sum[p[x]]; for (int i = 0; i < G[x].size(); i++) { int y = G[x][i]; h[y] ^= sum[p[y]]; sum[p[y]] = 0; } for (int i = 1; i <= n; i++) printf("%d ", h[i]); puts(""); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 10; const ll inf_ll = 1e18 + 10; const int N = 2e5 + 5; int h[N], f[N], l[N], v[N]; vector<int> adj[N]; void dfs(int i) { v[i] = 1; for (auto& j : adj[i]) { if (!v[j]) dfs(j); (l[i] = max(l[i], l[j] + 1)); } f[l[i]] ^= h[i]; } void dfs2(int i) { h[i] ^= f[l[i]]; for (auto& j : adj[i]) if (l[j] == l[i] - 1) { dfs2(j); break; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> h[i]; while (m--) { int x, y; cin >> x >> y; adj[x - 1].push_back(y - 1); } for (int i = 0; i < n; i++) if (!v[i]) dfs(i); if (*max_element(f, f + n) == 0) cout << "LOSE\n"; else { cout << "WIN\n"; int k = 0; for (int i = 0; i < n; i++) if (f[i] != 0) k = i; int r = 1 << (31 - __builtin_clz(f[k])); for (int i = 0; i < n; i++) if (l[i] == k && (r & h[i])) { dfs2(i); break; } for (int i = 0; i < n; i++) cout << h[i] << " \n"[i == n - 1]; } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool chkmin(T &x, T y) { return y < x ? (x = y, true) : false; } template <class T> bool chkmax(T &x, T y) { return y > x ? (x = y, true) : false; } struct __init { __init() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(16); cout << fixed; srand(time(0) ^ unsigned(unsigned long long(new char))); } } static __init__; const int maxn = 2e5 + 10; int n, m; int a[maxn]; vector<int> h[maxn]; bool vis[maxn]; int id[maxn], tot; void dfs(int x) { vis[x] = true; for (int v : h[x]) if (!vis[v]) dfs(v); id[++tot] = x; } int sg[maxn]; int xum[maxn]; void no() { cout << "LOSE\n"; exit(0); } int main() { cin >> n >> m; for (int i = 1; i <= (n); i++) cin >> a[i]; int u, v; for (int i = 1; i <= (m); i++) { cin >> u >> v; h[u].push_back(v); } for (int i = 1; i <= (n); i++) if (!vis[i]) dfs(i); for (int i = 1; i <= (n); i++) { int x = id[i]; memset(vis, 0, sizeof(bool) * (h[x].size() + 5)); for (int v : h[x]) vis[sg[v]] = true; for (int j = 0; j <= (n); j++) if (!vis[j]) { sg[x] = j; break; } } for (int i = 1; i <= (n); i++) xum[sg[i]] ^= a[i]; int Max = -1; for (int i = n; i >= (1); i--) if (xum[i]) { Max = i; break; } if (Max == -1) no(); memset(vis, 0, sizeof vis); for (int i = 1; i <= (n); i++) if (sg[i] == Max && (a[i] ^ xum[Max]) < a[i]) { a[i] ^= xum[Max]; for (int v : h[i]) if (sg[v] < Max && !vis[sg[v]]) { a[v] ^= xum[sg[v]]; vis[sg[v]] = true; } break; } cout << "WIN\n"; for (int i = 1; i <= (n); i++) cout << a[i] << ' '; cout << '\n'; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Main(),"Main",1<<27).start(); } void findCol(int i) { HashSet<Integer> set = new HashSet<>(); for(int j : adj[i]) { if(col[j] == -1) findCol(j); set.add(col[j]); } for(int j = 0; ; ++j) { if(!set.contains(j)) { col[i] = j; break; } } } ArrayList<Integer> adj[]; int col[]; public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int h[] = new int[n]; for(int i = 0; i < n; ++i) h[i] = sc.nextInt(); adj = new ArrayList[n]; for(int i = 0; i < n; ++i) adj[i] = new ArrayList<>(); for(int i = 0; i < m; ++i) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; adj[u].add(v); } col = new int[n]; Arrays.fill(col, -1); for(int i = 0; i < n; ++i) { if(col[i] == -1) findCol(i); } int xor[] = new int[n]; for(int i = 0; i < n; ++i) xor[col[i]] ^= h[i]; int curCol = -1; for(int i = 0; i < n; ++i) { if(xor[i] != 0) curCol = i; } if(curCol == -1) w.print("LOSE"); else { w.println("WIN"); int ind = -1; for(int i = 0; i < n; ++i) { if(col[i] == curCol) { if(ind == -1) ind = i; else if(h[i] > h[ind]) ind = i; } } h[ind] ^= xor[col[ind]]; for(int j : adj[ind]) { h[j] ^= xor[col[j]]; } for(int i : h) w.print(i + " "); } w.close(); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(long long a) { if (a < 0) { a = -a; putchar('-'); } if (a >= 10) write(a / 10); putchar('0' + a % 10); } inline void writeln(long long a) { write(a); puts(""); } inline void wri(long long a) { write(a); putchar(' '); } inline unsigned long long rnd() { return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4; } const int N = 100005; int h[N], dp[N], vis[N], to[N], rd[N], q[N]; vector<int> f[N], g[N]; int main() { int n = read(), m = read(); for (int i = (int)(1); i <= (int)(n); i++) h[i] = read(); for (int i = (int)(1); i <= (int)(m); i++) { int s = read(), t = read(); f[s].push_back(t); g[t].push_back(s); rd[s]++; } for (int i = (int)(1); i <= (int)(n); i++) if (!rd[i]) q[++*q] = i; for (int i = (int)(1); i <= (int)(*q); i++) { int t = q[i]; for (auto j : f[t]) vis[dp[j]] = 1; for (int j = 0;; j++) if (!vis[j]) { dp[t] = j; to[dp[t]] ^= h[t]; break; } for (auto j : f[t]) vis[dp[j]] = 0; for (auto j : g[t]) if (--rd[j] == 0) q[++*q] = j; } for (int i = (int)(n); i >= (int)(0); i--) if (to[i]) { puts("WIN"); for (int j = (int)(1); j <= (int)(n); j++) if ((h[j] ^ to[i]) < h[j]) { h[j] ^= to[i]; for (auto k : f[j]) { h[k] ^= to[dp[k]]; to[dp[k]] = 0; } break; } for (int i = (int)(1); i <= (int)(n); i++) wri(h[i]); puts(""); return 0; } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int mxN = 2e5; struct Edge { int v, nxt; } e[(mxN << 1) + 3]; int fe[mxN + 3]; int a[mxN + 3]; int f[mxN + 3], sg[mxN + 3]; int ind[mxN + 3]; bool vis[mxN + 3]; int n, m, en; void addedge(int u, int v) { en++; e[en].v = v; e[en].nxt = fe[u]; fe[u] = en; } void dfs(int u) { if (vis[u]) return; vis[u] = true; vector<int> apr; for (int i = fe[u]; i; i = e[i].nxt) { int v = e[i].v; dfs(v); apr.push_back(f[v]); } sort(apr.begin(), apr.end()); f[u] = 0; for (int i = 0; i < apr.size(); i++) { if (apr[i] == f[u]) { f[u]++; } else if (apr[i] > f[u]) { break; } } } int main() { n = read(), m = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= m; i++) { int u = read(), v = read(); ind[v]++; addedge(u, v); } for (int i = 1; i <= n; i++) { if (ind[i] == 0) { dfs(i); } } for (int i = 1; i <= n; i++) { sg[f[i]] ^= a[i]; } for (int i = n; i >= 0; i--) if (sg[i]) { puts("WIN"); for (int u = 1; u <= n; u++) if (f[u] == i && (a[u] ^ sg[i]) < a[u]) { a[u] ^= sg[i]; for (int o = fe[u]; o; o = e[o].nxt) { int v = e[o].v; a[v] ^= sg[f[v]]; sg[v] = 0; } break; } for (int u = 1; u <= n; u++) printf("%d ", a[u]); puts(""); return 0; } puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct Edge { int to, next; } edge[N]; int head[N], num; void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; } int sg[N]; vector<int> t[N]; int dfs(int x) { if (sg[x] != -1) return sg[x]; for (int i = head[x]; i; i = edge[i].next) t[x].push_back(dfs(edge[i].to)); sort(t[x].begin(), t[x].end()); if (!t[x].size()) sg[x] = 0; else { for (int i = 0; i <= t[x].size() - 1; i++) if (i != t[x][i]) { sg[x] = i; break; } if (sg[x] == -1) sg[x] = t[x].size(); } return sg[x]; } long long h[N], sh[N]; bool vv[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); add_edge(a, b); } memset(sg, -1, sizeof(sg)); for (int i = 1; i <= n; i++) sh[dfs(i)] ^= h[i]; bool flag = false; for (int i = 0; i <= n; i++) if (sh[i]) flag = true; if (flag) { printf("WIN\n"); int tmp = -1; for (int i = 1; i <= n; i++) if (tmp == -1 || sg[tmp] <= sg[i] && (h[i] ^ sh[sg[i]]) <= h[i]) tmp = i; h[tmp] ^= sh[sg[tmp]]; for (int i = head[tmp]; i; i = edge[i].next) if (!vv[sg[edge[i].to]]) { vv[sg[edge[i].to]] = true; h[edge[i].to] ^= sh[sg[edge[i].to]]; } for (int i = 1; i <= n; i++) printf("%lld ", h[i]); printf("\n"); } else printf("LOSE\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; vector<int> G[maxn]; int sg[maxn], deg[maxn], Xor[maxn], topo[maxn], mem[maxn], cnt; long long h[maxn], XOR[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%lld", &h[i]); for (int i = 0; i < m; ++i) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); ++deg[v]; } queue<int> q; for (int i = 1; i <= n; ++i) if (deg[i] == 0) q.push(i); while (!q.empty()) { int t = q.front(); q.pop(); topo[++cnt] = t; for (int i = 0; i < G[t].size(); ++i) { int c = G[t][i]; --deg[c]; if (!deg[c]) q.push(c); } } for (int i = n; i >= 1; --i) { int u = topo[i]; for (int j = 0; j < G[u].size(); ++j) { int c = G[u][j]; mem[sg[c]] = i; } while (sg[u] == i) ++sg[u]; XOR[sg[u]] ^= h[u]; } long long sghigh = -1; for (int i = 0; i < maxn; ++i) if (XOR[i] > 0) sghigh = i; if (sghigh == -1) return 0 * puts("LOSE"); for (int i = 1; i <= n; ++i) if (sg[i] == sghigh && (XOR[sghigh] ^ h[i]) < h[i]) { h[i] ^= XOR[sghigh]; for (int j = 0; j < G[i].size(); ++j) { int c = G[i][j]; h[c] ^= XOR[sg[c]]; XOR[sg[c]] = 0; } break; } printf("WIN\n"); for (int i = 1; i <= n; ++i) printf("%lld ", h[i]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct Edge { int to, next; } edge[N]; int head[N], num; void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; } int sg[N]; int dfs(int x) { if (sg[x] != -1) return sg[x]; vector<int> tmp, tmp0; for (int i = head[x]; i; i = edge[i].next) tmp.push_back(dfs(edge[i].to)); if (!tmp.size()) sg[x] = 0; else { sort(tmp.begin(), tmp.end()); tmp0.push_back(tmp[0]); for (int i = 1; i <= tmp.size() - 1; i++) if (tmp[i] != tmp[i - 1]) tmp0.push_back(tmp[i]); for (int i = 0; i <= tmp0.size() - 1; i++) if (i != tmp0[i]) { sg[x] = i; break; } if (sg[x] == -1) sg[x] = tmp0.size(); } return sg[x]; } long long h[N], sh[N]; bool vv[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); add_edge(a, b); } memset(sg, -1, sizeof(sg)); for (int i = 1; i <= n; i++) sh[dfs(i)] ^= h[i]; bool flag = false; for (int i = 0; i <= n; i++) if (sh[i]) flag = true; if (flag) { printf("WIN\n"); int tmp = -1; for (int i = 1; i <= n; i++) if (tmp == -1 || sg[tmp] <= sg[i] && (h[i] ^ sh[sg[i]]) <= h[i]) tmp = i; h[tmp] ^= sh[sg[tmp]]; for (int i = head[tmp]; i; i = edge[i].next) if (!vv[sg[edge[i].to]]) { vv[sg[edge[i].to]] = true; h[edge[i].to] ^= sh[sg[edge[i].to]]; } for (int i = 1; i <= n; i++) printf("%lld ", h[i]); printf("\n"); } else printf("LOSE\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int level[200005]; int h[200005]; int val[200005]; bool vis[200005]; bool num[200005]; vector<int> E[200005]; void dfs(int x) { if (vis[x]) return; vis[x] = true; if (E[x].size() == 0) level[x] = 0; int sz = E[x].size(); for (int v : E[x]) { if (!vis[v]) { dfs(v); } } for (int i = 0; i <= sz + 1; i++) num[i] = true; for (int v : E[x]) num[level[v]] = false; for (int i = 0; i <= sz + 1; i++) { if (num[i]) { level[x] = i; return; } } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); E[u].push_back(v); } for (int i = 1; i <= n; i++) level[i] = -1; for (int i = 1; i <= n; i++) vis[i] = false; for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(i); } int mx = 0; for (int i = 1; i <= n; i++) { mx = max(mx, level[i]); } for (int i = 0; i <= mx; i++) val[i] = 0; int choose = 0; for (int i = 1; i <= n; i++) { val[level[i]] ^= h[i]; } bool flag = true; for (int i = 0; i <= mx; i++) if (val[i] != 0) flag = false; if (flag) { puts("LOSE"); return 0; } for (int i = 1; i <= n; i++) { if (level[i] == mx) { if ((val[mx] ^ h[i]) < h[i]) { choose = i; break; } } } h[choose] = val[mx] ^ h[choose]; for (int v : E[choose]) { int x = level[v]; h[v] = val[x] ^ h[v]; } puts("WIN"); for (int i = 1; i <= n; i++) { printf("%d ", h[i]); } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int& x, int y, int mod = 998244353) { assert(y >= 0); x += y; if (x >= mod) x -= mod; assert(x >= 0 && x < mod); } void et(int x = -1) { printf("%d\n", x); exit(0); } long long fastPow(long long x, long long y, int mod = 998244353) { long long ans = 1; while (y > 0) { if (y & 1) ans = (x * ans) % mod; x = x * x % mod; y >>= 1; } return ans; } long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; } vector<int> mp[200135]; int h[200135], sg[200135], s[200135]; int spg(int x) { int& tmp = sg[x]; if (tmp != -1) return tmp; vector<int> vp; for (int c : mp[x]) vp.push_back(spg(c)); sort(vp.begin(), vp.end()); int N = unique(vp.begin(), vp.end()) - vp.begin(); for (int(i) = 0; (i) < (int)(N); (i)++) if (i != vp[i]) { tmp = i; return tmp; } tmp = N; return tmp; } void fmain(int tid) { scanf("%d%d", &n, &m); for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", h + i); for (int(i) = 1; (i) <= (int)(m); (i)++) { int u, v; scanf("%d%d", &u, &v); mp[u].push_back(v); } memset(sg, -1, sizeof sg); for (int(i) = 1; (i) <= (int)(n); (i)++) { s[spg(i)] ^= h[i]; } int tar = -1; for (int i = n; i >= 0; i--) if (s[i] != 0) { tar = i; break; } if (tar == -1) { puts("LOSE"); return; } puts("WIN"); int w = -1; for (int(i) = 1; (i) <= (int)(n); (i)++) if (sg[i] == tar) { if ((s[tar] ^ h[i]) < h[i]) { w = i; break; } } h[w] = s[tar] ^ h[w]; for (int c : mp[w]) { h[c] = s[sg[c]] ^ h[c]; } for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d ", h[i]); } int main() { int t = 1; for (int(i) = 1; (i) <= (int)(t); (i)++) { fmain(i); } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); int x = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar(); return x; } int n, m; const int _ = 2e5 + 7; int val[_], v[_]; vector<int> E[_]; int deg[_]; int st[_], top; int q[_], h[_]; bool used[_]; int main() { n = read(), m = read(); for (int i = 1; i <= n; ++i) v[i] = read(); for (int i = 1; i <= m; ++i) { int u = read(), v = read(); E[u].push_back(v); deg[v]++; } int l = 1, r = 0; for (int i = 1; i <= n; ++i) if (!deg[i]) q[++r] = i; while (l <= r) { int x = q[l++]; st[++top] = x; for (int i = 0; i < (int)E[x].size(); ++i) { int y = E[x][i]; deg[y]--; if (!deg[y]) q[++r] = y; } } while (top) { int x = st[top]; top--; for (int i = 0; i < (int)E[x].size(); ++i) { int y = E[x][i]; used[val[y]] = 1; } for (int i = 0; i <= m; ++i) { if (used[i]) continue; val[x] = i; break; } } int tag = 0; for (int i = 1; i <= n; ++i) h[val[i]] ^= v[i]; for (int i = 0; i <= m; ++i) tag |= h[i]; if (!tag) return puts("LOSE"), 0; puts("WIN"); int mx = 0; for (int i = 0; i <= m; ++i) { if (h[i]) mx = i; } for (int u = 1; u <= n; ++u) { if (val[u] == mx && (h[mx] ^ v[u]) < v[u]) { v[u] = h[mx] ^ v[u]; h[mx] = 0; for (int i = 0; i < (int)E[u].size(); ++i) { int y = E[u][i]; if (h[val[y]]) { v[y] = h[val[y]] ^ v[y]; h[val[y]] = 0; } } break; } } for (int i = 1; i <= n; ++i) printf("%d%c", v[i], " \n"[i == n]); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using i64 = long long; int n, m, h[223456], xors[223456], sg[223456], tag[223456]; int u, v, t, deg[223456], q[223456]; vector<int> e[223456]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &h[i]); } for (int i = 0; i < m; i++) { scanf("%d%d", &u, &v); e[u].push_back(v); ++deg[v]; } for (int i = 1; i <= n; i++) if (deg[i] == 0) q[++t] = i; for (int i = 1; i <= t; i++) { int u = q[i]; for (auto v : e[u]) { --deg[v]; if (deg[v] == 0) q[++t] = v; } } int maxL = 0; for (int i = n; i >= 1; i--) { int u = q[i]; for (auto v : e[u]) tag[sg[v]] = i; while (tag[sg[u]] == i) ++sg[u]; maxL = max(maxL, sg[u]); xors[sg[u]] ^= h[u]; } int lev = -1; for (int i = 0; i <= maxL; i++) if (xors[i] != 0) { lev = i; } if (lev == -1) { puts("LOSE"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (sg[u] == lev && (h[u] ^ xors[lev]) < h[u]) { h[u] = h[u] ^ xors[lev]; for (auto v : e[u]) { h[v] ^= xors[sg[v]]; xors[sg[v]] = 0; } } break; } for (int i = 1; i <= n; i++) printf("%d ", h[i]); puts(""); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, h[200205]; int info[200205], Prev[200205], to[200205], cnt_e; void Node(int u, int v) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v; } int in[200205], Q[200205], L, R, SG[200205], S[200205]; int vis[200205], tim, Mx; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), Node(u, v), in[v]++; for (int i = 1; i <= n; i++) if (!in[i]) Q[R++] = i; for (int now; L < R;) { now = Q[L++]; for (int i = info[now]; i; i = Prev[i]) { in[to[i]]--; if (!in[to[i]]) Q[R++] = to[i]; } } for (int i = R - 1; i >= 0; i--) { tim++; int u = Q[i]; for (int j = info[u]; j; j = Prev[j]) vis[SG[to[j]]] = tim; for (SG[u] = 0; vis[SG[u]] == tim; SG[u]++) ; S[SG[u]] ^= h[u]; Mx = max(Mx, SG[u]); } bool flg = 0; for (int i = 0; i <= n; i++) if (S[i] != 0) flg = 1; if (!flg) puts("LOSE"); else { puts("WIN"); int loc = 0, Maxloc = 0; for (int i = 0; i <= n; i++) if (S[i] != 0) loc = i; for (int i = 1; i <= n; i++) if (SG[i] == loc && (S[loc] ^ h[i]) < h[i]) Maxloc = i; h[Maxloc] = S[loc] ^ h[Maxloc]; for (int i = info[Maxloc]; i; i = Prev[i]) h[to[i]] = S[SG[to[i]]] ^ h[to[i]]; for (int i = 1; i <= n; i++) printf("%d%c", h[i], i == n ? '\n' : ' '); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
/* real time: 2021.7.2 hh:2021.5.8 gugu: 2 months */ #include<bits/stdc++.h> #define R register #define N 1000201 #define ll long long int du[N],n,m; int home[N],next[N],to[N],cnt; ll a[N],X[N],qwq[N]; int zu[N],va[N],q[N],l,r; inline void add(int a,int b){ next[++cnt]=home[a],home[a]=cnt,to[cnt]=b,++du[b]; } int main(){ scanf("%d%d",&n,&m); for(R int i=1;i<=n;++i) scanf("%lld",&a[i]),qwq[i]=a[i]; //刺刺蘑菇 for(R int i=1;i<=m;++i){ R int s,t;scanf("%d%d",&s,&t);add(s,t); } l=1,r=0; for(R int i=1;i<=n;++i) if(!du[i]) q[++r]=i; while(l<=r){ R int u=q[l++]; for(R int i=home[u];i;i=next[i]){ R int v=to[i]; if(!--du[v]) q[++r]=v; } } for(R int _=n;_>=1;--_){ R int u=q[_]; for(R int i=home[u];i;i=next[i]) va[zu[to[i]]]=1; R int mxx=0; while(va[mxx]) ++mxx; zu[u]=mxx,X[mxx]^=a[u]; for(R int i=home[u];i;i=next[i]) va[zu[to[i]]]=0; } R int ps=-1; for(R int i=0;i<=n;++i) if(X[i]!=0) ps=i; if(!(~ps)){ printf("LOSE"); return 0; } printf("WIN\n"); for(R int i=1;i<=n;++i) if(zu[i]==ps){ if((X[ps]^a[i])>a[i]) continue; qwq[i]=(X[ps]^a[i]); for(R int j=home[i];j;j=next[j]){ R int v=to[j]; if(zu[v]<ps) qwq[v]=(X[zu[v]]^a[v]); } break; } for(R int i=1;i<=n;++i) printf("%lld ",qwq[i]); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int level[200005]; int h[200005]; int val[200005]; bool vis[200005]; bool num[200005]; vector<int> E[200005]; void dfs(int x) { if (vis[x]) return; vis[x] = true; if (E[x].size() == 0) level[x] = 0; int sz = E[x].size(); for (int v : E[x]) { if (!vis[v]) { dfs(v); } } for (int i = 0; i <= sz + 1; i++) num[i] = true; for (int v : E[x]) num[level[v]] = false; for (int i = 0; i <= sz + 1; i++) { if (num[i]) { level[x] = i; return; } } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); E[u].push_back(v); } for (int i = 1; i <= n; i++) level[i] = -1; for (int i = 1; i <= n; i++) vis[i] = false; for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(i); } int mx = 0; for (int i = 0; i <= mx; i++) val[i] = 0; int choose = 0; for (int i = 1; i <= n; i++) { val[level[i]] ^= h[i]; } for (int i = 1; i <= n; i++) { if (val[level[i]] != 0) mx = max(mx, level[i]); } bool flag = true; for (int i = 0; i <= mx; i++) if (val[i] != 0) flag = false; if (flag) { puts("LOSE"); return 0; } for (int i = 1; i <= n; i++) { if (level[i] == mx) { if ((val[mx] ^ h[i]) < h[i]) { choose = i; break; } } } h[choose] = val[mx] ^ h[choose]; for (int v : E[choose]) { int x = level[v]; h[v] = val[x] ^ h[v]; } puts("WIN"); for (int i = 1; i <= n; i++) { printf("%d ", h[i]); } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#pragma optimize("unroll-loops,no-stack-protector") #include<bits/stdc++.h> #define pb emplace_back #define fi first #define se second #define debug(...) fprintf(stderr,__VA_ARGS__) #define ALL(a) a.begin(),a.end() #define lowbit(x) ((x)&-(x)) using namespace std; typedef unsigned long long u64; typedef unsigned int u32; typedef pair<int,int>pii; typedef vector<int>VI; typedef long long i64; typedef long long ll; typedef double ld; namespace io{ struct eof{eof(){}}; const int L=(1<<21)|5; char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,qu[55];int f,qr; #define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++) inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;} inline void putc(char x){*oS++=x;if(oS==oT)flush();} template<class I>inline void gi(I&x){ for(f=1,c=gc();(c<'0'||c>'9')&&(c!=EOF);c=gc())if(c=='-')f=-1; if(c==EOF)throw eof(); for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f; } template<class I>inline void print(I x){ if(!x)putc('0');if(x<0)putc('-'),x=-x; while(x)qu[++qr]=x%10+'0',x/=10;while(qr)putc(qu[qr--]); } #if __cplusplus < 201103L // do nothing #else struct StringReader{ function<bool(char)>chk; StringReader(){chk=[&](char c){return c<='z'&&c>='a';};} StringReader(function<bool(char)>func){chk=func;} inline char read(){for(c=gc();!chk(c);c=gc());return c;} inline void gs(char*s){for(c=gc();!chk(c);c=gc());for(;chk(c);c=gc())*s++=c;*s=0;} }; #endif inline void ps(const char*s){int l=strlen(s),x;for(x=0;x<l;x++)putc(s[x]);} struct IOC{~IOC(){flush();}}ioc; inline double readld(){ double x=0,y=1; for(c=gc();c<'0'||c>'9';c=gc())if(c=='-')y=-1;assert(c!='.'); for(;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=y;assert(c!='e'); if(c=='.')for(c=gc();c<='9'&&c>='0';c=gc())y*=0.1,x+=y*(c&15); return x; } inline void printld(double x,int y){ if(x<0)putc('-'),x=-x;x+=.5*pow(.1,y);print((u64)x),putc('.'); for(x-=(u64)x;y;--y)x*=10,putc((int)x+'0'),x-=(int)x; } }using io::gi;using io::print;using io::putc; template<class T>int ctz(T a){return sizeof(T)>4?__builtin_ctzll(a):__builtin_ctz(a);} template<class T>inline T gcd(T a,T b){ int shift=ctz(a|b); for(b>>=ctz(b),a>>=ctz(a);a;a-=b,a>>=ctz(a))if(a<b)swap(a,b); return b<<shift; } template<class T>void exgcd(T a,T b,T&x,T&y){ if(!b)return (void)(x=1,y=0); exgcd(b,a%b,y,x),y-=a/b*x; } template<class T>T Inv(T a,T p){T x,y;exgcd(a,p,x,y);return (x%p+p)%p;} inline int fpow(int a,int t,int p){static int r;for(r=1;t;a=(ll)a*a%p,t>>=1)if(t&1)r=(ll)r*a%p;return r;} string to_string(string s){return '"'+s+'"';}; string to_string(const char*s){return to_string(string(s));} string to_string(bool f){return f?"true":"false";} template<class A,class B>string to_string(pair<A,B>p){return "("+to_string(p.fi)+", "+to_string(p.se)+")";} template<class T>string to_string(T v){string s="{",e="";for(auto&x:v)s+=e+to_string(x),e=", ";s+="}";return s;} void debug_out(){cerr<<endl;}template<class A,class...B>void debug_out(A x,B...y){cerr<<" "<<to_string(x),debug_out(y...);} void scan(){}template<class A,class...B>void scan(A&a,B&...b){gi(a),scan(b...);} template<class T>void read(T first,T last){for(;first!=last;++first)gi(*first);} template<class T>void write(T first,T last){for(;first!=last;putc(++first==last?'\n':' '))print(*first);} template<class T>void show(T x){print(x),putc('\n');} template<class A,class...B>void show(A a,B...b){print(a),putc(' '),show(b...);} template<class T>inline T abs(T x){return x<0?-x:x;} template<class T> bool chkmin(T &x,T y){ return y<x?x=y,true:false; } template<class T> bool chkmax(T &x,T y){ return x<y?x=y,true:false; } const int N=2e5+5; int n,m,in[N],sg[N]; i64 h[N],layer[N]; vector<int> adj[N]; int main(){ int u,v; scan(n,m); read(h+1,h+n+1); queue<int> q; vector<int> topo; for(int i=1;i<=m;++i) scan(u,v),adj[u].pb(v),in[v]++; for(int i=1;i<=n;++i) if(!in[i]) q.push(i); while(q.size()){ u=q.front(); topo.pb(u); q.pop(); for(int v:adj[u]) if(!--in[v]) q.push(v); } reverse(ALL(topo)); for(int x:topo){ set<int> nxt; for(int y:adj[x]) nxt.insert(sg[y]); while(nxt.count(sg[x])) ++sg[x]; layer[sg[x]]^=h[x]; } for(u=n;u>=0;--u) if(layer[u]) { puts("WIN"); for(v=1;v<=n;++v) if(sg[v]==u) break; h[v]^=layer[u]; layer[u]=0; for(int x:adj[v]) h[x]^=layer[sg[x]],layer[sg[x]]=0; write(h+1,h+n+1); exit(0); } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int read(); int n, m; vector<int> e[200005]; int deg[200005]; void add(int f, int t) { e[f].push_back(t), ++deg[t]; } queue<int> q; int h[200005], sg[200005], mx, sum[200005]; vector<int> nx[200005]; void work() { for (int i = 1; i <= n; ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(), sort(nx[u].begin(), nx[u].end()); for (int x : nx[u]) if (x > sg[u]) break; else if (x == sg[u]) ++sg[u]; sg[u] > mx ? mx = sg[u] : 0; for (int v : e[u]) nx[v].push_back(sg[u]), --deg[v] ? void() : q.push(v); } for (int i = 1; i <= n; ++i) sum[sg[i]] ^= h[i]; for (int i = 1; i <= mx; ++i) if (sum[i]) return puts("WIN"), void(); puts("LOSE"), void(); } int vis[200005]; void solve(int d) { int u; for (u = 1; u <= n; ++u) if (sg[u] == d && h[u] > (sum[d] ^ h[u])) break; h[u] = sum[d] ^ h[u]; for (int v = 1; v <= n; ++v) { if (sum[sg[v]]) { int flg = 0; for (int t : e[v]) if (t == u) flg = 1, h[v] = sum[sg[v]] ^ h[v]; if (!flg) continue; sum[sg[v]] = 0; } } for (int i = 1; i <= n; ++i) printf("%d ", h[i]); } int main() { n = read(), m = read(); for (int i = 1; i <= n; ++i) h[i] = read(); for (int i = 1; i <= m; ++i) add(read(), read()); work(); for (int i = mx; i >= 0; --i) if (sum[i]) return solve(i), 0; return 0; } int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename tp> inline void read(tp &x) { x = 0; char c = getchar(); int f = 0; for (; c < '0' || c > '9'; f |= c == '-', c = getchar()) ; for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar()) ; if (f) x = -x; } const int N = 3e5 + 233; int n, m, h[N], vis[N], sg[N], sum[N]; vector<int> G[N]; inline void dfs(int u) { if (vis[u]) return; vis[u] = true; vector<int> mark(G[u].size() + 1, 0); for (int v : G[u]) { dfs(v); if (sg[v] <= G[u].size()) mark[sg[v]] = true; } while (mark[sg[u]]) sg[u]++; sum[sg[u]] ^= h[u]; } int main(void) { read(n); read(m); for (register int i = 1; i <= (n); i++) read(h[i]); for (register int i = 1; i <= (m); i++) { int x, y; read(x); read(y); G[x].push_back(y); } for (register int i = 1; i <= (n); i++) if (!vis[i]) dfs(i); for (int i = n; i >= 1; i--) if (sum[i]) { cout << "WIN\n"; for (register int k = 1; k <= (n); k++) if (sg[k] == i && h[k] > (h[k] ^ sum[i])) { auto flip = [](int x) { h[x] ^= sum[sg[x]]; sum[sg[x]] = 0; }; flip(k); for (int v : G[k]) flip(v); break; } for (register int k = 1; k <= (n); k++) cout << h[k] << " \n"[k == n]; return 0; } cout << "LOSE\n"; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int N = 200007; int a[N], deg[N], pos[N], vis[N], sg[N], s[N]; std::queue<int> q; std::vector<int> e[N]; int read() { int x = 0, c = getchar(); while (isspace(c)) c = getchar(); while (isdigit(c)) (x *= 10) += c & 15, c = getchar(); return x; } int main() { int n = read(), m = read(); for (int i = 1; i <= n; ++i) a[i] = read(); for (int i = 1, u, v; i <= m; ++i) u = read(), v = read(), e[u].push_back(v), ++deg[v]; for (int i = 1; i <= n; ++i) if (!deg[i]) q.push(i); for (int u, c = 0; !q.empty();) { u = q.front(), q.pop(), pos[++c] = u; for (int v : e[u]) if (!--deg[v]) q.push(v); } for (int i = n, u; i; --i) { u = pos[i]; for (int v : e[u]) vis[sg[v]] = i; while (vis[sg[u]] == i) ++sg[u]; s[sg[u]] ^= a[u]; } for (int i = n, u; ~i; --i) if (s[i]) { for (int j = 1; j <= n; ++j) if (sg[j] == i && a[j] > s[i] ^ a[j]) u = j; a[u] ^= s[i]; for (int v : e[u]) a[v] ^= s[sg[v]], s[sg[v]] = 0; puts("WIN"); for (int j = 1; j <= n; ++j) printf("%d ", a[j]); puts(""); return 0; } puts("LOSE"); }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.lang.reflect.Field; import java.util.OptionalInt; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); EElectionPromises solver = new EElectionPromises(); solver.solve(1, in, out); out.close(); } } static class EElectionPromises { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.ri(); int m = in.ri(); Node[] nodes = new Node[n]; for (int i = 0; i < n; i++) { nodes[i] = new Node(); nodes[i].h = in.ri(); } for (int i = 0; i < m; i++) { Node a = nodes[in.ri() - 1]; Node b = nodes[in.ri() - 1]; a.adj.add(b); } int[] sg = new int[n]; for (int i = 0; i < n; i++) { sg[dist(nodes[i])] ^= nodes[i].h; } int max = Arrays.stream(sg).max().orElse(-1); if (max == 0) { out.println("LOSE"); return; } out.println("WIN"); int maxIndex = 0; for (int i = 0; i < n; i++) { if (sg[i] > 0) { maxIndex = i; } } Node end = null; for (Node node : nodes) { if (dist(node) == maxIndex && (node.h ^ sg[maxIndex]) < node.h) { end = node; break; } } while (end != null) { end.h ^= sg[dist(end)]; end = end.next; } for (Node node : nodes) { out.append(node.h).append(' '); } } public int dist(Node root) { if (root.dist == -1) { root.dist = 0; for (Node node : root.adj) { if (dist(node) + 1 > root.dist) { root.dist = dist(node) + 1; root.next = node; } } } return root.dist; } } static class FastInput { private final InputStream is; private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int ri() { return readInt(); } public int readInt() { boolean rev = false; skipBlank(); if (next == '+' || next == '-') { rev = next == '-'; next = read(); } int val = 0; while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } return rev ? val : -val; } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 32 << 10; private OutputStream writer; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); private static Field stringBuilderValueField; private char[] charBuf = new char[THRESHOLD * 2]; private byte[] byteBuf = new byte[THRESHOLD * 2]; static { try { stringBuilderValueField = StringBuilder.class.getSuperclass().getDeclaredField("value"); stringBuilderValueField.setAccessible(true); } catch (Exception e) { stringBuilderValueField = null; } stringBuilderValueField = null; } public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(OutputStream writer) { this.writer = writer; } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(int c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println(String c) { return append(c).println(); } public FastOutput println() { return append('\n'); } public FastOutput flush() { try { if (stringBuilderValueField != null) { try { byte[] value = (byte[]) stringBuilderValueField.get(cache); writer.write(value, 0, cache.length()); } catch (Exception e) { stringBuilderValueField = null; } } if (stringBuilderValueField == null) { int n = cache.length(); if (n > byteBuf.length) { //slow writer.write(cache.toString().getBytes(StandardCharsets.UTF_8)); // writer.append(cache); } else { cache.getChars(0, n, charBuf, 0); for (int i = 0; i < n; i++) { byteBuf[i] = (byte) charBuf[i]; } writer.write(byteBuf, 0, n); } } writer.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { writer.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } static class Node { List<Node> adj = new ArrayList<>(); Node next; int h; int dist = -1; } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << "<" << x.first << ", " << x.second << ">"; } template <class n> auto operator<<(ostream &p, n y) -> typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type { int o = 0; p << "{"; for (auto c : y) { if (o++) p << ", "; p << c; } return p << "}"; } void dor() { cerr << endl; } template <class n, class... second> void dor(n p, second... y) { cerr << p << " "; dor(y...); } template <class n, class second> void mini(n &p, second y) { if (p > y) p = y; } template <class n, class second> void maxi(n &p, second y) { if (p < y) p = y; } const int M = 1024 * 256; int H[M], mex[M]; int n, m, out[M], xo[M]; vector<int> V[M], T[M]; int main() { scanf("%d%d", &n, &m); for (int i = (1); i <= (int)(n); ++i) { scanf("%d", H + i); } for (int i = (1); i <= (int)(m); ++i) { int a, b; scanf("%d%d", &a, &b); V[a].push_back(b); T[b].push_back(a); out[a]++; } queue<int> Q; for (int i = (1); i <= (int)(n); ++i) { if (out[i] == 0) { Q.push(i); } } while (!Q.empty()) { int v = Q.front(); Q.pop(); vector<int> X; for (auto x : V[v]) { X.push_back(mex[x]); } sort((X).begin(), (X).end()); X.push_back(1e9); for (int i = (0); i <= (int)((int)(X).size() - 1); ++i) { if (X[i] != i) { mex[v] = i; break; } } for (auto x : T[v]) { out[x]--; if (out[x] == 0) { Q.push(x); } } xo[mex[v]] ^= H[v]; } int t = -1; for (int i = (0); i <= (int)(n); ++i) { if (xo[i] != 0) { t = i; } } if (t == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (int i = (1); i <= (int)(n); ++i) { if (mex[i] != t || (xo[t] ^ H[i]) >= H[i]) { continue; } H[i] = xo[t] ^ H[i]; for (auto x : V[i]) { if (xo[mex[x]] != 0) { H[x] = xo[mex[x]] ^ H[x]; xo[mex[x]] = 0; } } } for (int i = (1); i <= (int)(n); ++i) { printf("%d ", H[i]); } printf("\n"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Main(),"Main",1<<27).start(); } void findCol(int i) { HashSet<Integer> set = new HashSet<>(); for(int j : adj[i]) { if(col[j] == -1) findCol(j); set.add(col[j]); } for(int j = 0; ; ++j) { if(!set.contains(j)) { col[i] = j; break; } } } ArrayList<Integer> adj[]; int col[]; public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int h[] = new int[n]; for(int i = 0; i < n; ++i) h[i] = sc.nextInt(); adj = new ArrayList[n]; for(int i = 0; i < n; ++i) adj[i] = new ArrayList<>(); for(int i = 0; i < m; ++i) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; adj[u].add(v); } col = new int[n]; Arrays.fill(col, -1); for(int i = 0; i < n; ++i) { if(col[i] == -1) findCol(i); } int xor[] = new int[n]; for(int i = 0; i < n; ++i) xor[col[i]] ^= h[i]; int curCol = -1; for(int i = 0; i < n; ++i) { if(xor[i] != 0) curCol = i; } if(curCol == -1) w.print("LOSE"); else { w.println("WIN"); int ind = -1; for(int i = 0; i < n; ++i) { if(col[i] == curCol) { if(ind == -1) ind = i; else if(h[i] > h[ind]) ind = i; } } h[ind] ^= xor[col[ind]]; xor[col[ind]] = 0; for(int j : adj[ind]) { h[j] ^= xor[col[j]]; xor[col[j]] = 0; } for(int i : h) w.print(i + " "); } w.close(); } }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAXN = 200010; vector<int> x[MAXN], y[MAXN]; int v[MAXN], out[MAXN], sg[MAXN]; int xr[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a; --b; x[a].push_back(b); y[b].push_back(a); ++out[a]; } queue<int> Q; for (int i = 0; i < n; ++i) { if (out[i] == 0) Q.push(i); } int maxsg = 0; while (!Q.empty()) { int a = Q.front(); Q.pop(); for (int b : y[a]) { --out[b]; if (out[b] == 0) { Q.push(b); } } set<int> s; for (int b : x[a]) s.insert(sg[b]); for (int i = 0; i < n; ++i) { if (s.find(i) == s.end()) { sg[a] = i; break; } } maxsg = max(maxsg, sg[a]); } for (int i = 0; i < n; ++i) { xr[sg[i]] ^= v[i]; } bool win = false; for (int i = maxsg; i >= 0; --i) { if (xr[i] != 0) { win = true; int p = -1; for (int j = 0; j < n; ++j) { if (sg[j] != i) continue; if (p == -1 || v[p] < v[j]) p = j; } xr[i] ^= v[p]; v[p] = xr[i]; xr[i] = 0; for (int b : x[p]) { if (xr[sg[b]] != 0) { v[b] ^= xr[sg[b]]; xr[sg[b]] = 0; } } break; } } if (win) { cout << "WIN\n"; for (int i = 0; i < n; ++i) cout << v[i] << " "; cout << '\n'; } else { cout << "LOSE\n"; } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; vector<int> V[maxn], H[maxn]; int n, m; long long a[maxn]; int SG[maxn]; int h[maxn]; int maxx = 0; int dfs(int u) { if (SG[u] != -1) return SG[u]; vector<int> tmp; for (auto v : V[u]) { tmp.push_back(dfs(v)); } sort(tmp.begin(), tmp.end()); int j = 0; for (int i = 0;; i++) { if (tmp.size() == 0 || tmp[j] != i || j >= tmp.size()) { SG[u] = i; break; } while (j < tmp.size() && tmp[j] == i) j++; } maxx = max(maxx, SG[u]); return SG[u]; } int c[maxn]; void solve(int x) { for (auto i : H[x]) { if (a[i] ^ h[x] < a[i]) { a[i] = a[i] ^ h[x]; for (auto j : V[i]) { if (c[SG[j]]) continue; c[SG[j]] = 1; a[j] ^= h[SG[j]]; } break; } } } int main() { memset(SG, -1, sizeof(SG)); cin >> n >> m; int sum = 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), sum ^= a[i]; for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); V[u].push_back(v); } if (!sum) { puts("LOSE"); return 0; } puts("WIN"); for (int i = 1; i <= n; i++) { if (SG[i] == -1) dfs(i); } for (int i = 1; i <= n; i++) { h[SG[i]] ^= a[i]; H[SG[i]].push_back(i); } int p; for (int i = maxx; i >= 0; i--) { if (h[i]) { p = i; solve(i); break; } } for (int i = 1; i <= n; i++) cout << a[i] << " "; return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int h[212345]; vector<vector<int> > graph; vector<int> mex; vector<int> xors; int get_mex(int v) { if (mex[v] != -1) return mex[v]; vector<bool> seen(graph[v].size(), false); for (auto u : graph[v]) { int val = get_mex(u); if (val < seen.size()) seen[val] = true; } for (mex[v] = 0; mex[v] < seen.size(); mex[v]++) { if (!seen[mex[v]]) break; } return mex[v]; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &h[i]); graph.resize(n); while (m--) { int a, b; scanf("%d%d", &a, &b); a--; b--; graph[a].push_back(b); } mex.resize(n, -1); for (int i = 0; i < n; i++) { get_mex(i); } xors.resize(n, 0); int maxmex = 0; for (int i = 0; i < n; i++) { maxmex = max(maxmex, mex[i]); xors[mex[i]] ^= h[i]; } int non_zero_mex = -1; for (int i = maxmex; i >= 0; i--) { if (xors[i] != 0) { non_zero_mex = i; break; } } if (non_zero_mex == -1) { printf("LOSE\n"); return 0; } int v; for (v = 0; v < n; v++) { if (mex[v] == non_zero_mex) if (xors[mex[v]] ^ h[v] < h[v]) break; } h[v] ^= xors[mex[v]]; xors[mex[v]] = 0; for (auto u : graph[v]) { if (xors[mex[u]] != 0) { h[u] ^= xors[mex[u]]; xors[mex[u]] = 0; } } printf("WIN\n"); for (int i = 0; i < n; i++) { printf("%d%c", h[i], (i + 1) == n ? '\n' : ' '); } return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define mp make_pair #define all(a) begin(a),end(a) #define FOR(x,val,to) for(int x=(val);x<int((to));++x) #define FORE(x,val,to) for(auto x=(val);x<=(to);++x) #define FORR(x,arr) for(auto &x: arr) #define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x) #define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x) #define REE(s_) {cout<<s_<<'\n';exit(0);} #define GET(arr) for(auto &i: (arr)) sc(i) #define whatis(x) cerr << #x << " is " << (x) << endl; #define e1 first #define e2 second #define INF 0x7f7f7f7f typedef std::pair<int,int> pi; typedef std::vector<int> vi; typedef std::vector<std::string> vs; typedef int64_t ll; typedef uint64_t ull; #define umap unordered_map #define uset unordered_set using namespace std; using namespace __gnu_pbds; #ifdef ONLINE_JUDGE #define whatis(x) ; #endif #ifdef _WIN32 #define getchar_unlocked() _getchar_nolock() #define _CRT_DISABLE_PERFCRIT_LOCKS #endif template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; } template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; } template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; } template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; } inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;} inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}} inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}} template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); } template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define N 1000001 vi adj[N]; ll a[N]; int leafd[N]; ll xr[N]; ll resa[N]; int mex(vi &vec){ sort(all(vec)); vec.erase(unique(all(vec)),vec.end()); if(vec.empty() || vec[0] != 0) return 0; FOR(i,1,vec.size()){ if(vec[i] != vec[i-1] + 1){ return vec[i-1] + 1; } } return vec.back() + 1; } void d1(int v){ /* leafd[v] = 0; */ /* FORR(i,adj[v]){ */ /* /1* d1(i); *1/ */ /* if(leafd[i] == -1){ */ /* d1(i); */ /* } */ /* leafd[v] = max(leafd[v], leafd[i] + 1); */ /* } */ /* xr[leafd[v]] ^= a[v]; */ vi vec; FORR(i,adj[v]){ /* d1(i); */ if(leafd[i] == -1){ d1(i); } vec.push_back(leafd[i]); /* leafd[v] = max(leafd[v], leafd[i] + 1); */ } leafd[v] = mex(vec); xr[leafd[v]] ^= a[v]; } // that can be reached from v using a single road omg xd // passes 6 cases while having thought that just any reachability is fine // fix -> mex adj leafd (czy ich mexów wsm?) // mexów i guess // -> WA8 lol // no tak, bo nie zaktualizowałem d2() // chociaż wait, w tym teście: // 3 0 // 4 1 4 // nie powinno to mieć znaczenia right? /* void d2(int v){ */ void d2(int v, bool nxt = 1){ // wait, przecież tutaj jak jestem rootem to nie mogę tego zwiększać xd // (musi być zmniejszone exactly) // -> choose taki spośród all rootów o (w sumie dowolnym, niekoniecznie // najwyższym?) leafd, aby dało się go zmniejszyć żeby xor na tej pozycji // był 0 // w sumie musi być z max leafd nvmind // no i fix że tylko raz idę do adj typów // no i do all adj, nie tylko do jednego pathu // -> na pałe check all z max leafd czy po zmianie jest mniejsze, musi // jakiś taki być def resa[v] = a[v] ^ xr[leafd[v]]; /* whatis(v) */ /* whatis(leafd[v]) */ /* if(leafd[v] == 0) */ if(!nxt) return; /* pi mx = {-1,-1}; */ FORR(i,adj[v]){ d2(i,0); /* mx = max(mx, mp(leafd[i],i)); */ } /* d2(mx.e2); */ } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,m; sc(n,m); FOR(i,0,n) sc(a[i]); int f,s; FOR(i,0,m){ sc(f,s); --f,--s; adj[f].pb(s); // lol /* adj[s].pb(f); */ } memset(leafd,-1,n << 2); FOR(i,0,n){ if(leafd[i] == -1){ d1(i); } } int tp = -1; FOR(i,0,n){ if(xr[i]){ tp = i; } } if(tp == -1){ cout << "LOSE\n"; } else{ cout << "WIN\n"; memcpy(resa,a,n << 3); FOR(i,0,n){ /* if(leafd[i] == tp){ */ /* tp = i; */ /* break; */ /* } */ // musi być zmniejszone if(leafd[i] == tp && ((a[i] ^ xr[tp]) < a[i])){ tp = i; break; } } d2(tp); FOR(i,0,n){ cout << resa[i] << ' '; } cout << '\n'; } // WA7 }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; vector<int> V[maxn], H[maxn]; int n, m; long long a[maxn]; int SG[maxn]; int h[maxn]; int maxx = 0; int dfs(int u) { if (SG[u] != -1) return SG[u]; vector<int> tmp; for (auto v : V[u]) { tmp.push_back(dfs(v)); } sort(tmp.begin(), tmp.end()); int j = 0; for (int i = 0;; i++) { if (tmp.size() == 0 || tmp[j] != i || j >= tmp.size()) { SG[u] = i; break; } while (j < tmp.size() && tmp[j] == i) j++; } maxx = max(maxx, SG[u]); return SG[u]; } int c[maxn]; void solve(int x) { for (auto i : H[x]) { if ((a[i] ^ h[x]) < a[i]) { a[i] = a[i] ^ h[x]; for (auto j : V[i]) { if (c[SG[j]]) continue; c[SG[j]] = 1; a[j] ^= h[SG[j]]; } break; } } } int main() { memset(SG, -1, sizeof(SG)); cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); V[u].push_back(v); } for (int i = 1; i <= n; i++) { if (SG[i] == -1) dfs(i); } for (int i = 1; i <= n; i++) { h[SG[i]] ^= a[i]; H[SG[i]].push_back(i); } int p; int flag; for (int i = maxx; i >= 0; i--) { if (h[i]) { flag = 1; p = i; solve(i); break; } } if (flag) { puts("WIN"); for (int i = 1; i <= n; i++) cout << a[i] << " "; } else puts("LOSE"); return 0; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> std::vector<std::vector<int>> ad; std::vector<int> fm; std::vector<bool> tmp; int f(int x) { if (fm[x] >= 0) return fm[x]; for (int y : ad[x]) f(y); for (int y : ad[x]) tmp[fm[y]] = true; fm[x] = int(std::find(begin(tmp), end(tmp), false) - begin(tmp)); for (int y : ad[x]) { tmp[fm[y]] = false; } return fm[x]; } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; std::vector<int> h(n); for (int& x : h) std::cin >> x; ad.resize(n); for (int z = m; z--;) { int u, v; std::cin >> u >> v; --u; --v; ad[u].push_back(v); } std::vector<int> val(n); fm.resize(n); tmp.resize(n); for (int i = n; i--;) val[f(i)] ^= h[i]; while (!val.empty() && val.back() == 0) val.pop_back(); if (val.empty()) { std::cout << "LOSE\n"; return 0; } std::cout << "WIN\n"; int i = 0; while (fm[i] != val.size() - 1 || (h[i] ^ val.back()) > h[i]) { ++i; } h[i] ^= val.back(); std::vector<bool> ok(val.size() - 1); for (int j : ad[i]) if ((unsigned)fm[j] < ok.size() && !ok[fm[j]]) { ok[fm[j]] = true; h[j] ^= val[fm[j]]; } for (auto x : h) std::cout << x << ' '; std::cout << '\n'; }
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n" ], "output": [ "LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n" ] }
{ "input": [ "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n" ], "output": [ "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long large = 2000000000000000000LL; vector<int> dp; vector<vector<int> > adj; int f(int u) { if (dp[u] != -1) return dp[u]; vector<int> ch; for (int j = 0; j < (int)adj[u].size(); j++) { int v = adj[u][j]; ch.push_back(f(v)); } sort(ch.begin(), ch.end()); int re = 0; for (int i = 0; i < (int)ch.size(); i++) { if (ch[i] == re) re++; else if (ch[i] > re) break; } dp[u] = re; return dp[u]; } int main() { int n, m; cin >> n >> m; vector<int> h(n, 0); for (int i = 0; i < n; i++) scanf("%d", &h[i]); adj.assign(n, vector<int>()); for (int i = 0; i < m; i++) { int x, y; scanf("%d%d", &x, &y); x--; y--; adj[x].push_back(y); } dp.assign(n, -1); int ans = 0; int sz = 0; for (int i = 0; i < n; i++) sz = max(sz, f(i) + 1); vector<int> tp(sz, 0); for (int i = 0; i < n; i++) tp[f(i)] ^= h[i]; for (int i = 0; i < sz; i++) ans |= tp[i]; if (ans == 0) { cout << "LOSE" << endl; return 0; } int p = -1; for (int i = 0; i < sz; i++) { if (tp[i]) p = i; } for (int i = 0; i < n; i++) if (f(i) == p) { h[i] ^= tp[p]; tp[p] = 0; for (int j = 0; j < (int)adj[i].size(); j++) { int v = adj[i][j]; h[v] ^= tp[f(v)]; tp[f(v)] = 0; } break; } cout << "WIN" << endl; for (int i = 0; i < n; i++) cout << h[i] << " "; cout << endl; return 0; }