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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using cd = complex<double>; constexpr int maxn = 2e5 + 10; vector<int> vec[maxn] = {}; int n; int longest_path[maxn] = {}, parities[maxn] = {}; vector<int> topo_sort() { vector<int> in_deg(n); for (auto& x : vec) for (auto y : x) in_deg[y]++; queue<int> de_viz; for (int i = 0; i < n; ++i) if (in_deg[i] == 0) de_viz.push(i); vector<int> ret; while (!de_viz.empty()) { auto curr = de_viz.front(); de_viz.pop(); ret.push_back(curr); for (auto next : vec[curr]) if (--in_deg[next] == 0) de_viz.push(next); } return ret; } bool viz[maxn] = {}; void dfs(int x) { viz[x] = 1; for (auto y : vec[x]) if (!viz[y]) dfs(y); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int m; cin >> n >> m; vector<int> h(n); for (auto& x : h) cin >> x; for (int i = 0, x, y; i < m; ++i) { cin >> x >> y; vec[x - 1].push_back(y - 1); } auto ts = topo_sort(); reverse(begin(ts), end(ts)); for (auto x : ts) for (auto& next : vec[x]) longest_path[x] = max(longest_path[x], longest_path[next] + 1); for (int i = 0; i < n; ++i) parities[longest_path[i]] ^= h[i]; int which_parity = n; while (which_parity >= 0 && parities[which_parity] == 0) --which_parity; if (which_parity == -1) { cout << "LOSE" << endl; return 0; } int which = 0; for (int i = 0; i < n; ++i) { if (longest_path[i] != which_parity) continue; if (h[i] <= (h[i] ^ parities[which_parity])) continue; which = i; break; } h[which] = (h[which] ^ parities[which_parity]); parities[which_parity] = 0; dfs(which); for (int i = 0; i < n; ++i) { if (viz[i]) { h[i] ^= parities[longest_path[i]]; parities[longest_path[i]] = 0; } } cout << "WIN" << endl; for (int i = 0; i < n; ++i) cout << 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 = 200005; int n, m, cnt, l = 1, r, mx, s, h[N], hea[N], nxt[N], to[N], hea1[N], nxt1[N], to1[N], d[N], q[N], vis[N], g[N], f[N]; inline int read() { char c = getchar(); int ans = 0; while (c < 48 || c > 57) c = getchar(); while (c >= 48 && c <= 57) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar(); return ans; } inline void write(int x) { int num = 0; char sc[15]; if (!x) sc[num = 1] = 48; while (x) sc[++num] = x % 10 + 48, x /= 10; while (num) putchar(sc[num--]); putchar(' '); } inline void add(int x, int y) { nxt[++cnt] = hea[x], to[cnt] = y, hea[x] = cnt; nxt1[cnt] = hea1[y], to1[cnt] = x, hea1[y] = cnt, ++d[x]; } int main() { n = read(), m = read(); for (register int i = 1; i <= n; ++i) h[i] = read(); for (register int i = 0; i < m; ++i) { int u = read(), v = read(); add(u, v); } for (register int i = 1; i <= n; ++i) if (!d[i]) q[++r] = i; while (l <= r) { int x = q[l++]; for (register int i = hea[x]; i; i = nxt[i]) vis[g[to[i]]] = x; while (vis[g[x]] == x) ++g[x]; if (g[x] > mx) mx = g[x]; f[g[x]] ^= h[x]; for (register int i = hea1[x]; i; i = nxt1[i]) { int u = to1[i]; if (!(--d[u])) q[++r] = u; } } for (register int i = mx; i; --i) if (f[i]) { s = i; break; } puts(s ? "WIN" : "LOSE"); if (!s) return 0; for (register int i = 1; i <= n; ++i) if (g[i] == s && (h[i] ^ f[s]) < h[i]) { h[i] ^= f[s], s = i; break; } for (register int i = hea[s]; i; i = nxt[i]) { int u = to[i]; if (f[g[u]]) h[u] ^= f[g[u]], f[g[u]] = 0; } for (register int i = 1; i <= n; ++i) write(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 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"); // if((H[i] ^ grundy2[grundy[i]]) >= H[i]){ // H[i] ^= grundy2[grundy[i]]; // grundy2[grundy[i]] = 0; // } H[i] ^= grundy2[grundy[i]]; grundy2[grundy[i]] = 0; } cout<<H[i]<<" "; } cout<<endl; // cout<<(394273396 ^ 395063145 ^ 789789)<<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 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"); bool boo = false; for (int i = (1); i <= (int)(n); ++i) { if (mex[i] != t || (xo[t] ^ H[i]) >= H[i]) { continue; } boo = true; 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; } assert(boo); 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> using namespace std; int n, m; int a[200000 + 5]; vector<int> E[200000 + 5]; int ind[200000 + 5]; int rk[200000 + 5]; int sg[200000 + 5]; void topo() { static bool vis[200000 + 5]; queue<int> q; vector<int> seq; for (int i = 1; i <= n; i++) if (ind[i] == 0) q.push(i); while (!q.empty()) { int x = q.front(); q.pop(); seq.push_back(x); for (int y : E[x]) { ind[y]--; if (ind[y] == 0) q.push(y); } } for (int i = seq.size() - 1; i >= 0; i--) { int x = seq[i]; for (int y : E[x]) vis[rk[y]] = 1; while (vis[rk[x]]) rk[x]++; for (int y : E[x]) vis[rk[y]] = 0; } } int main() { int u, v; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { scanf("%d %d", &u, &v); E[u].push_back(v); ind[v]++; } topo(); for (int i = 1; i <= n; i++) sg[rk[i]] ^= a[i]; int pos = -1; for (int i = 0; i <= n; i++) { if (sg[i] != 0) { pos = i; break; } } if (pos == -1) puts("LOSE"); else { puts("WIN"); for (int i = 1; i <= n; i++) { if (rk[i] == pos) { if ((sg[rk[i]] ^ a[i]) <= a[i]) { a[i] ^= sg[rk[i]]; sg[rk[i]] = 0; for (int y : E[i]) { a[y] ^= sg[rk[y]]; sg[rk[y]] = 0; } } } } for (int i = 1; i <= n; i++) printf("%d ", a[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 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++) { 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; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; break; } } if (!f) { puts("LOSE"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (mex[u] == tmp && a[u] ^ nim[tmp] < a[u]) { a[u] = nim[mex[u]] ^= a[u]; for (int v : e[u]) { if (nim[mex[v]]) a[v] = nim[mex[v]] ^= a[v]; } 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> 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 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] > h[pos]) pos = i; 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> const int N = 200200; using namespace std; int n; int q; int h[N]; int m[N]; int t[N]; vector<int> v[N]; void dfs(int x) { if (t[x]) { return; } set<int> s; for (int y : v[x]) { dfs(y); s.insert(t[y]); } t[x] = 1; while (s.find(t[x]) != s.end()) { t[x] += 1; } } int main() { ios_base::sync_with_stdio(0); cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> h[i]; } for (int i = 1; i <= q; i++) { int x, y; cin >> x >> y; v[x].push_back(y); } for (int i = 1; i <= n; i++) { dfs(i); m[t[i]] ^= h[i]; } int last = -1; for (int i = 1; i <= n; i++) { if (m[i]) { last = i; } } if (last == -1) { cout << "LOSE" << "\n"; return 0; } cout << "WIN" << "\n"; for (int i = 1; i <= n; i++) { if (t[i] == last && (m[t[i]] ^ h[i]) < h[i]) { h[i] = m[t[i]] ^ h[i]; for (int j : v[i]) { m[t[j]] ^= h[j]; h[j] = m[t[j]]; m[t[j]] = 0; } } } for (int i = 1; i <= n; i++) { cout << h[i] << " \n"[i == 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 n, m, h[200005]; int info[200005], Prev[200005], to[200005], cnt_e; void Node(int u, int v) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v; } int in[200005], Q[200005], L, R, SG[200005], S[200005]; int vis[200005], 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 = n - 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 <= Mx; i++) if (S[i] != 0) flg = 1; if (!flg) puts("LOSE"); else { puts("WIN"); int loc = 0, Max = 0, Maxloc; for (int i = 0; i <= Mx; i++) if (S[i] != 0) loc = i; for (int i = 1; i <= n; i++) if (SG[i] == loc && Max < h[i]) Max = 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
#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] && h[mx] < h[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; const int prime = 999983; const int INF = 0x7FFFFFFF; const long long INFF = 0x7FFFFFFFFFFFFFFF; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-6; const long long mod = 1e9 + 7; long long qpow(long long a, long long b) { long long s = 1; while (b > 0) { if (b & 1) s = s * a % mod; a = a * a % mod; b >>= 1; } return s; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1}; const int maxn = 2e5 + 10; vector<int> G[maxn]; int topo[maxn]; int sg[maxn], deg[maxn], mem[maxn]; int Xor[maxn]; long long h[maxn]; int main(void) { int n, m; cin >> 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); G[u].push_back(v); deg[v]++; } queue<int> q; int cnt = 1; for (int i = 1; i <= n; ++i) if (deg[i] == 0) q.push(i); while (!q.empty()) { int p = q.front(); q.pop(); topo[cnt++] = p; for (auto c : G[p]) { deg[c]--; if (deg[c] == 0) q.push(c); } } for (int i = n; i >= 1; --i) { int u = topo[i]; for (auto c : G[u]) mem[sg[c]] = i; while (mem[sg[u]] == i) sg[u]++; Xor[sg[u]] ^= h[i]; } int index = -1; for (int i = 0; i < maxn; ++i) if (Xor[i] != 0) index = i; if (index == -1) return 0 * puts("LOSE"); for (int i = 1; i <= n; ++i) { if (sg[i] == index && ((h[i] ^ Xor[index]) < h[i])) { h[i] ^= Xor[index]; for (auto c : G[i]) { h[c] ^= Xor[sg[c]]; Xor[sg[c]] = 0; } break; } } puts("WIN"); 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 = 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]); } } 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" ] }
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 n, m, h[200005]; int info[200005], Prev[200005], to[200005], cnt_e; void Node(int u, int v) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v; } int in[200005], Q[200005], L, R, SG[200005], S[200005]; int vis[200005], 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 = n - 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[SG[i]] ^ h[i]) < h[i]) Maxloc = i; h[Maxloc] = S[loc] ^ h[Maxloc]; for (int i = info[Maxloc]; i; i = Prev[i]) if (SG[to[i]] < loc) 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
#include <bits/stdc++.h> using namespace std; const int Q = 1 << 18; struct gra { int las[Q], e[Q], nn[Q], inc; void ins(int x, int y) { e[++inc] = y; nn[inc] = las[x]; las[x] = inc; } } g, f; int mex[Q]; int vis[Q]; int h[Q], sm[Q]; int q[Q]; int in[Q]; 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, x, y; i <= m; i++) scanf("%d%d", &x, &y), g.ins(x, y), f.ins(y, x), ++in[x]; int hd = 1, tl = 0; for (int i = 1; i <= n; i++) if (!in[i]) q[++tl] = i; for (int t = 1; t <= n; t++) { int x = q[hd++]; for (int t = g.las[x]; t; t = g.nn[t]) { int y = g.e[t]; vis[mex[y]] = x; } for (mex[x] = 0; vis[mex[x]] == x; ++mex[x]) ; for (int t = f.las[x]; t; t = f.nn[t]) { int y = f.e[t]; --in[y]; if (!in[y]) q[++tl] = y; } } int flag = 0; for (int i = 1; i <= n; i++) sm[mex[i]] ^= h[i]; for (int p = n; p; --p) if (sm[p]) { puts("WIN"); for (int i = 1; i <= n; i++) if (mex[i] == p && (h[i] ^ sm[p]) < h[i]) { h[i] ^= sm[p]; for (int t = g.las[i]; t; t = g.nn[t]) { int y = g.e[t]; if (vis[mex[y]] == n + 1) continue; vis[mex[y]] = n + 1; h[y] ^= sm[mex[y]]; } 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; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 200005; int h[N], q[N], dp[N], in[N], f[N], vis[N]; int n, m, l, r, u, v, p; vector<int> e[N]; int main() { read(n), read(m), p = n; for (int i = (1); i <= (n); i++) read(h[i]); for (int i = (1); i <= (m); i++) read(u), read(v), e[u].push_back(v), in[v]++; for (int i = (1); i <= (n); i++) if (!in[i]) q[r++] = i; for (int u = q[l++]; l <= r; u = q[l++]) for (auto v : e[u]) if (!(--in[v])) q[r++] = v; for (int i = (n - 1); i >= (0); i--) { int u = q[i]; for (auto v : e[u]) vis[dp[v]] = 1; while (vis[dp[u]]) dp[u]++; for (auto v : e[u]) vis[dp[v]] = 0; f[dp[u]] ^= h[u]; } while (p >= 0 && !f[p]) p--; if (p == -1) return puts("LOSE"), 0; for (int u = (1); u <= (n); u++) if (dp[u] == p && (h[u] ^ f[p]) < h[u]) { h[u] ^= f[p]; for (auto v : e[u]) h[v] ^= f[dp[v]], f[dp[v]] = 0; } puts("YES"); 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; 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; num[0] = true; int sz = E[x].size(); for (int i = 1; i <= sz + 1; i++) num[i] = true; for (int v : E[x]) { if (!vis[v]) { dfs(v); } 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("YES"); 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; 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"); if (n == 700 && m == 200000) { cout << Max << " " << maxx << endl; } 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; int n, q; char s[200005]; int Arb[1000005][7], Lazy[1000005]; void add(int nod, int v) { Lazy[nod] += v; Arb[nod][1] += v; Arb[nod][2] -= v; Arb[nod][4] -= v; Arb[nod][5] -= 2 * v; } void propag(int nod) { add(nod * 2, Lazy[nod]); add(nod * 2 + 1, Lazy[nod]); Lazy[nod] = 0; } void merge(int nod, int nod1, int nod2) { Arb[nod][1] = max(Arb[nod1][1], Arb[nod2][1]); Arb[nod][2] = max(max(Arb[nod1][2], Arb[nod2][2]), Arb[nod1][1] + Arb[nod2][5]); Arb[nod][3] = max(max(Arb[nod1][3], Arb[nod2][3]), max(Arb[nod1][1] + Arb[nod2][4], Arb[nod1][2] + Arb[nod2][1])); Arb[nod][4] = max(max(Arb[nod1][4], Arb[nod2][4]), Arb[nod1][5] + Arb[nod2][1]); Arb[nod][5] = max(Arb[nod1][5], Arb[nod2][5]); } void update(int x, int y, int ad, int st = 1, int dr = n, int nod = 1) { if (x <= st && dr <= y) { add(nod, ad); return; } propag(nod); int mij = (st + dr) / 2; if (x <= mij) update(x, y, ad, st, mij, nod * 2); if (mij + 1 <= y) update(x, y, ad, mij + 1, dr, nod * 2 + 1); merge(nod, nod * 2, nod * 2 + 1); } int main() { scanf("%d%d", &n, &q); scanf("%s", s + 1); n = 2 * (n - 1); for (int i = 1; i <= n; ++i) { if (s[i] == '(') update(i, n, 1); else update(i, n, -1); } printf("%d\n", Arb[1][3]); int x, y; while (q--) { scanf("%d%d", &x, &y); if (s[x] == s[y]) { printf("%d\n", Arb[1][3]); continue; } swap(s[x], s[y]); if (s[x] == '(') update(x, n, 2); else update(x, n, -2); if (s[y] == '(') update(y, n, 2); else update(y, n, -2); printf("%d\n", Arb[1][3]); } 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; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 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, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c < '0' || c > '9'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) if (c == '-') f = -1; for (x = 0; c <= '9' && c >= '0'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) x = (x << 1) + (x << 3) + (c & 15); x *= f; } template <class I> inline void get(I &x) { for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c < 'A' || c > 'Z'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) ; x = c; } inline void read(char *s) { for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++); c < 'A' || c > 'Z'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) ; for (; c >= 'A' && c <= 'Z'; c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)) *++s = c; *++s = '\0'; } 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--]); } struct Flusher_ { ~Flusher_() { flush(); } } io_flusher_; } // namespace io using io ::get; using io ::gi; using io ::print; using io ::putc; using io ::read; const int N = 2e5 + 5; vector<int> e[N], v[N]; int deg[N], q[N], num[N], vis[N]; long long h[N], val[N]; int main() { register int n, m, i, x, y, l, r, cnt; gi(n); gi(m); for (i = 1; i <= n; ++i) gi(h[i]); while (m--) gi(x), gi(y), ++deg[x], e[y].push_back(x), v[x].push_back(y); l = 1; r = 0; for (i = 1; i <= n; ++i) if (!deg[i]) q[++r] = i; cnt = 0; while (l <= r) { x = q[l++]; for (auto y : v[x]) vis[num[y]] = 1; while (vis[num[x]]) ++num[x]; for (auto y : v[x]) vis[num[y]] = 0; cnt = max(cnt, num[x]); for (auto y : e[x]) if (!--deg[y]) q[++r] = y; } for (i = 1; i <= n; ++i) val[num[i]] ^= h[i]; for (i = cnt; i >= 0; --i) if (val[i]) { putc('W'); putc('I'); putc('N'); putc('\n'); for (x = 1; x <= n; ++x) if (num[x] == i && h[x] > (h[x] ^ val[i])) { h[x] ^= val[i]; for (auto y : v[x]) h[y] ^= val[num[y]]; for (i = 1; i <= n; ++i) print(h[i]), putc(' '); putc('\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" ] }
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; 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 = 1; 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" ] }
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; 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 (w == -1 || h[i] > h[w]) w = i; } 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; struct ahowwogaw { int v, next; } _[1000005]; int head[1000005], tot = 1, zyl[200005], yihuo[1000005], a[1000005]; bool have[1000005], qwer[1000005]; int fyr(int iakioi) { if (zyl[iakioi] >= 0) { return zyl[iakioi]; } int i, ykb = 0; for (i = head[iakioi]; i; i = _[i].next) { have[ykb++] = 0; } have[ykb] = 0; for (i = head[iakioi]; i; i = _[i].next) { have[fyr(_[i].v)] = 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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct Edge { int to, next; } edge[N * 2]; 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; for (int i = head[x]; i; i = edge[i].next) tmp.push_back(dfs(edge[i].to)); sort(tmp.begin(), tmp.end()); if (!tmp.size()) sg[x] = 0; else { for (int i = 0; i <= tmp.size() - 1; i++) if (i != tmp[i]) { sg[x] = i; break; } if (sg[x] == -1) sg[x] = tmp.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] || (sg[tmp] == sg[i] && h[tmp] < 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> ve1[maxn], ve2[maxn]; int rd[maxn]; int n, m; int sm[maxn], h[maxn]; queue<int> q; int mx[maxn]; int vis[maxn]; vector<int> veo[maxn]; bool mark[maxn]; void ptans() { for (int i = 1; i <= n; i++) { printf("%d ", h[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 x, y; scanf("%d%d", &x, &y); ve1[x].push_back(y); ve2[y].push_back(x); rd[x]++; } for (int i = 1; i <= n; i++) { if (!rd[i]) q.push(i); } while (q.size()) { int x = q.front(); q.pop(); for (auto y : ve1[x]) { vis[mx[y]] = x; } for (auto y : ve2[x]) { if (--rd[y] == 0) q.push(y); } for (mx[x] = 0; vis[mx[x]] == x; ++mx[x]) ; } for (int i = 1; i <= n; i++) { sm[mx[i]] ^= h[i]; veo[mx[i]].push_back(i); } for (int p = n; p >= 0; --p) { if (sm[p]) { puts("WIN"); for (auto x : veo[p]) { if ((h[x] ^ sm[p]) < h[x]) { h[x] ^= sm[p]; for (auto y : ve1[x]) { if (mark[mx[y]]) continue; mark[mx[y]] = 1; h[y] ^= sm[mx[y]]; } } } ptans(); 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; 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, t[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) { 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> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector<int> h(n); for (auto&& v : h) { std::cin >> v; } std::vector<std::vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; std::cin >> u >> v; g[u - 1].push_back(v - 1); } std::vector<bool> visited(n); std::vector<int> sorted_graph; sorted_graph.reserve(n); std::function<void(int)> dfs = [&](int index) { visited[index] = true; for (const auto& child : g[index]) { if (!visited[child]) dfs(child); } sorted_graph.push_back(index); }; for (int i = 0; i < n; i++) { if (!visited[i]) dfs(i); } std::vector<int> xors(n); std::vector<int> level(n); for (const auto& vertex : sorted_graph) { const auto& children = g[vertex]; std::vector<int> child_levels(children.size()); std::transform(children.begin(), children.end(), child_levels.begin(), [&](int child) { return level[child]; }); std::sort(child_levels.begin(), child_levels.end()); child_levels.erase(std::unique(child_levels.begin(), child_levels.end()), child_levels.end()); int mex = 0; while (mex < (int)child_levels.size() && mex == child_levels[mex]) { mex++; } level[vertex] = mex; xors[mex] ^= h[vertex]; } auto it = std::find_if(xors.rbegin(), xors.rend(), [](int x) { return x; }); if (it == xors.rend()) { std::cout << "LOSE\n"; return 0; } int highest_level = xors.rend() - it - 1; std::cout << "WIN\n"; for (int i = 0; i < n; i++) { if (level[i] == highest_level && (h[i] ^ *it) < h[i]) { h[i] ^= *it; for (const auto& child : g[i]) { h[child] ^= xors[level[child]]; xors[level[child]] = 0; } } } std::copy(h.begin(), h.end(), std::ostream_iterator<int>(std::cout, " ")); 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]; ans[sg[i]] ^= a[i]; } int pd = 0; for (int i = (0); i <= (n); ++i) pd |= ans[i], maxx = (ans[i] > 0 ? i : maxx); for (int i = (1); i <= (n); ++i) if (sg[i] == maxx && (ans[maxx] ^ a[i]) < a[i]) { id = i; break; } if (!pd) return puts("LOSE"), 0; assert(id != -1); puts("WIN"); a[id] ^= ans[sg[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; int n, m, SG[100005], Mx, h[100005], sum[100005]; bool vis[100005]; int fir[100005], nxt[100005], to[100005], 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] > h[id]) id = i; h[id] ^= sum[k]; for (int i = fir[id]; i; i = nxt[i]) h[to[i]] ^= sum[SG[to[i]]]; 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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, m, i, j, t, k, s, head[maxn], N, in[maxn], b[maxn], sg[maxn]; long long a[maxn], val[maxn]; bool vis[maxn]; struct Edge { int nxt, aim; } edge[maxn]; inline void add_edge(int x, int y) { edge[++N] = (Edge){head[x], y}; head[x] = N; } queue<int> Q; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; ++i) scanf("%lld", &a[i]); for (i = 1; i <= m; ++i) { scanf("%d%d", &t, &k); add_edge(t, k); ++in[k]; } for (i = 1; i <= n; ++i) if (!in[i]) Q.push(i); k = 0; while (!Q.empty()) { t = Q.front(); Q.pop(); b[++k] = t; for (i = head[t]; i; i = edge[i].nxt) { int des = edge[i].aim; --in[des]; if (!in[des]) Q.push(des); } } for (i = n; i > 0; --i) { for (j = head[b[i]]; j; j = edge[j].nxt) vis[sg[edge[j].aim]] = 1; t = 0; while (vis[t]) ++t; sg[b[i]] = t; val[t] ^= a[b[i]]; for (j = head[b[i]]; j; j = edge[j].nxt) vis[sg[edge[j].aim]] = 0; } t = -1; for (i = 1; i <= n; ++i) if (val[i] > 0) t = i; if (t == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (i = 1; i <= n; ++i) if (sg[i] == t && (a[i] ^ val[sg[i]]) < a[i]) { a[i] ^= val[sg[i]]; for (j = head[i]; j; j = edge[j].nxt) { a[edge[j].aim] ^= val[sg[edge[j].aim]]; val[sg[edge[j].aim]] = 0; } break; } for (i = 1; i <= n; ++i) printf("%lld%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; 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; } cout << now << endl; 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> using namespace std; const int maxn = 200005; int n, m, i, j, t, k, s, head[maxn], N, in[maxn], b[maxn], sg[maxn]; long long a[maxn], val[maxn]; bool vis[maxn]; struct Edge { int nxt, aim; } edge[maxn]; inline void add_edge(int x, int y) { edge[++N] = (Edge){head[x], y}; head[x] = N; } queue<int> Q; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; ++i) scanf("%lld", &a[i]); for (i = 1; i <= m; ++i) { scanf("%d%d", &t, &k); add_edge(t, k); ++in[k]; } for (i = 1; i <= n; ++i) if (!in[i]) Q.push(i); k = 0; while (!Q.empty()) { t = Q.front(); Q.pop(); b[++k] = t; for (i = head[t]; i; i = edge[i].nxt) { int des = edge[i].aim; --in[des]; if (!in[des]) Q.push(des); } } for (i = n; i > 0; --i) { for (j = head[b[i]]; j; j = edge[j].nxt) vis[sg[edge[j].aim]] = 1; t = 0; while (vis[t]) ++t; sg[b[i]] = t; val[t] ^= a[b[i]]; for (j = head[b[i]]; j; j = edge[j].nxt) vis[sg[edge[j].aim]] = 0; } t = -1; for (i = 1; i <= n; ++i) if (val[i] > 0) t = i; if (t == -1) { printf("LOSE\n"); return 0; } printf("WIN\n"); for (i = 1; i <= n; ++i) if (sg[i] == t && (a[i] ^ val[sg[i]]) < a[i]) { a[i] ^= val[sg[i]]; val[sg[i]] = 0; for (j = head[i]; j; j = edge[j].nxt) { a[edge[j].aim] ^= val[sg[edge[j].aim]]; val[sg[edge[j].aim]] = 0; } break; } for (i = 1; i <= n; ++i) printf("%lld%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; struct Edge { int t, next; Edge() {} Edge(int a, int b) : t(a), next(b) {} }; Edge e[200005], e2[200005]; int head[200005], head2[200005], du[200005]; int dep[200005]; queue<int> q1, q2; int topo(int n) { for (int i = 1; i <= n; i++) if (!du[i]) q1.push(i); int d = 0; while (!q1.empty()) { d++; while (!q2.empty()) q2.pop(); while (!q1.empty()) { int x = q1.front(); q1.pop(); dep[x] = d; for (int i = head2[x]; i; i = e[i].next) { int u = e2[i].t; du[u]--; if (!du[u]) q2.push(u); } } swap(q1, q2); } return d; } int num[200005], sum[200005]; void solve(int x, int d) { num[x] ^= sum[d]; for (int i = head[x]; i; i = e[i].next) if (dep[e[i].t] == dep[x] - 1) { solve(e[i].t, d - 1); return; } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); e[i] = Edge(y, head[x]); head[x] = i; e2[i] = Edge(x, head2[y]); head2[y] = i; du[x]++; } int d = topo(n); for (int i = 1; i <= n; i++) sum[dep[i]] ^= num[i]; bool ok = 0; for (int i = 1; i <= d; i++) if (sum[i]) ok = 1; if (!ok) { puts("LOSE"); return 0; } puts("WIN"); for (int i = d; i > 0; i--) if (sum[i]) { for (int j = 1; j <= n; j++) if (dep[j] == i) { solve(j, i); break; } break; } for (int i = 1; i <= n; i++) printf("%d ", num[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; long long n, m, num[200100], sy[200100], ds[200100], bj[200100], sum[200100]; vector<long long> to[200100], pre[200100]; queue<long long> que; int main() { long long i, j, t, p, q; cin >> 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); for (; !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 >= 1; 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]]) 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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int N = 200200; const long long mod = 998244353; using namespace std; int n; int m; int a[N]; int M[N]; int h[N]; vector<int> v[N]; void dfs(int x) { if (M[x]) { return; } int res = 1; set<int> s; for (int y : v[x]) { dfs(y); s.insert(M[y]); } while (s.find(res) != s.end()) { res += 1; } M[x] = res; } int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; v[x].push_back(y); } for (int i = 1; i <= n; i++) { if (!M[i]) { dfs(i); } h[M[i]] ^= a[i]; } int res = 0; for (int i = 1; i < N; i++) { if (h[i]) { res = i; } } if (res == 0) { cout << "LOSE" << "\n"; return 0; } cout << "WIN" << "\n"; int pos = -1; for (int i = 1; i <= n; i++) { if (M[i] == res) { if (pos == -1 || a[i] > a[pos]) { pos = i; } } } a[pos] ^= h[res]; for (int y : v[pos]) { if (M[y] < res) { h[M[y]] ^= a[y]; a[y] = h[M[y]]; h[M[y]] = 0; } } for (int i = 1; i <= n; i++) { cout << a[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; const int N=200005; int n,m,h[N],q[N],d[N],s[N],vis[N],sg[N]; vector<int>g[N]; 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);g[u].push_back(v);d[v]++;} int ql=1,qr=0; for(int i=1;i<=n;i++)if(!d[i])q[++qr]=i; while(ql<=qr) { int x=q[ql++]; for(int i=0;i<g[x].size();i++)if(!--d[g[x][i]])q[++qr]=g[x][i]; } for(int i=n;i;i--) { int x=q[i]; for(int j=0;j<g[x].size();j++)vis[sg[g[x][j]]]=i; while(vis[sg[x]]==i)sg[x]++;s[sg[x]]^=h[x]; } for(int i=n;~i;i--)if(s[i]) { int x;for(int j=1;j<=n;j++)if(sg[j]==i&&h[j]>(s[i]^h[j]))x=j; for(int j=0;j<g[x].size();j++)h[g[x][j]]^=s[sg[g[x][j]]],s[sg[g[x][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; int h[200000]; vector<int> node[200000]; int done[200000]; vector<int> topo; void dfs(int p) { if (done[p]++) return; for (int i : node[p]) { dfs(i); } topo.push_back(p); } int grundy[200000]; int grundy2[200000]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> h[i]; while (m--) { int a, b; cin >> a >> b; a--, b--; node[a].push_back(b); } for (int i = 0; i < n; i++) dfs(i); for (int p : topo) { vector<int> v; for (int i : node[p]) v.push_back(grundy[i]); sort(v.begin(), v.end()); int x = 0; while (binary_search(v.begin(), v.end(), x)) x++; grundy[p] = x; grundy2[x] ^= h[p]; } int high = 0; long long lose = 1; for (int i = 0; i < n; i++) if (grundy2[i]) { lose = 0; high = max(high, grundy[i]); } if (lose) { cout << "LOSE" << endl; return 0; } for (int p = 0; p < n; p++) { int x = grundy[p]; if (x == high && (h[p] >> 31 - __builtin_clz(grundy2[x]) & 1)) { assert(grundy2[x] >> 31 - __builtin_clz(grundy2[x]) & 1); h[p] ^= grundy2[x]; grundy2[x] = 0; for (int i : node[p]) { h[i] ^= grundy2[grundy[i]]; grundy2[grundy[i]] = 0; } cout << "WIN" << endl; for (int i = 0; i < n; i++) cout << h[i] << ' '; cout << 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; 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], e0[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); e0[v].push_back(u); } for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(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; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; 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; 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 = max_element(tot, tot + n + 1) - tot; 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
#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){ int fl = -1; for(int j = 63; j >= 0; j--){ if((H[i] & grundy2[grundy[i]]) & 1ll<<(j)){ fl = j; break; } } int msk = 0; for(int j = fl; j >= 0; j--){ msk ^= (grundy2[grundy[i]] & 1ll<<j); } dbg(hi, i, grundy[i], grundy2[grundy[i]], msk); grundy2[grundy[i]] ^= msk; H[i] ^= msk; }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 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], e0[maxn]; set<int> val[maxn]; set<int>::iterator it; queue<int> q; int in[maxn], a[maxn], mex[maxn], nim[maxn], n, m; 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); e0[v].push_back(u); in[u]++; } for (int i = 1; i <= n; i++) { if (!in[i]) q.push(i); } while (!q.empty()) { int u = q.front(); q.pop(); it = val[u].begin(); for (int i = 1; i <= n; i++) { if (it == val[u].end() || *it != i) { mex[u] = i; break; } else { it++; } } for (int v : e0[u]) { in[v]--; val[v].insert(mex[u]); if (!in[v]) q.push(v); } } for (int i = 1; i <= n; i++) { nim[mex[i]] ^= a[i]; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; 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; 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++) { 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; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; break; } } if (!f) { puts("LOSE"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (mex[u] == tmp && a[u] ^ nim[tmp] < a[u]) { a[u] = nim[mex[u]] ^= a[u]; for (int v : e[u]) { a[v] = nim[mex[v]] ^= a[v]; } 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> 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 && get_high(h[i]) == get_high(sum[mx])) pos = i; 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
#pragma GCC optimize ("O3", "unroll-loops") //#pragma GCC target ("avx2") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin()) #define pb push_back #define mp make_pair #define F first #define S second #define CASE(x) int x; cin >> x; while (x--) #define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc) using namespace std; using namespace __gnu_pbds; namespace { const int MOD107 = 1000000007; const int MOD998 = 998244353; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <class T> using maxheap = priority_queue<T, vector<T>, less<T>>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); struct Modular { private: long long MODVALUE = 0; long long val = 0; Modular initModular(long long val) const { return Modular(val, MODVALUE); } #ifdef LOCAL inline void validate() const { assert(MODVALUE != 0); } inline void validate(const Modular& other) const { assert(MODVALUE != 0); assert(MODVALUE == other.MODVALUE); other.validate(); } #else inline void validate() const { } inline void validate(const Modular& other) const { } #endif public: explicit operator long long() const { return val; } template<class T> Modular& operator = (const T& other) { val = other; return *this; } template<class T> void setMod(const T& MOD) { MODVALUE = MOD; } Modular& operator += (const Modular& other) { validate(other); val += other.val; val %= MODVALUE; return *this; } Modular operator + (const Modular& other) { Modular tmp = *this; return tmp += other; } template<class T> Modular& operator += (const T& other) { return *this += initModular(other); } template<class T> Modular operator + (const T& other) { return *this + initModular(other); } template<class T> friend Modular operator + (const T& other, const Modular& m) { return m.initModular(other) + m; } Modular& operator ++() { return *this += 1; } Modular operator ++(int) { Modular tmp = *this; ++*this; return tmp; } Modular operator - () const { return initModular(-val); } Modular& operator -= (const Modular& other) { validate(other); val -= other.val; val += MODVALUE; val %= MODVALUE; return *this;} Modular operator - (const Modular& other) { Modular tmp = *this; return tmp -= other; } template<class T> Modular& operator -= (const T& other) { return *this -= initModular(other); } template<class T> Modular operator - (const T& other) { return *this - initModular(other); } template<class T> friend Modular operator - (const T& other, const Modular& m) { return m.initModular(other) - m; } Modular& operator --() { return *this -= 1; } Modular operator --(int) { Modular tmp = *this; --*this; return tmp; } Modular& operator *= (const Modular& other) { validate(other); val *= other.val; val %= MODVALUE; val += MODVALUE; val %= MODVALUE; return *this; } Modular operator * (const Modular& other) { Modular tmp = *this; return tmp *= other; } template<class T> Modular& operator *= (const T& other) { return *this *= initModular(other); } template<class T> Modular operator * (const T& other) { return *this * initModular(other); } template<class T> friend Modular operator * (const T& other, const Modular& m) { return m.initModular(other) * m; } Modular pow(long long power) const { Modular m = *this, ans = initModular(1); while (power) { if (power & 1) ans *= m; m *= m; power >>= 1; } return ans; } Modular pow(const Modular& other) const { return pow(other.val); } Modular inv() const { return pow(MODVALUE - 2); } Modular& operator /= (const Modular& other) { val *= other.inv().val; val %= MODVALUE; return *this; } Modular operator / (const Modular& other) { Modular tmp = *this; return tmp /= other; } template<class T> Modular& operator /= (const T& other) { return *this /= initModular(other); } template<class T> Modular operator / (const T& other) { return *this / initModular(other); } template<class T> friend Modular operator / (const T& other, const Modular& m) { return m.initModular(other) / m; } friend istream& operator >> (istream& in, Modular& m) { in >> m.val; m.val %= m.MODVALUE; m.val += m.MODVALUE; m.val %= m.MODVALUE; return in; } friend ostream& operator << (ostream& out, const Modular& m) { return out << m.val; } Modular() { val = 0; MODVALUE = 0; } Modular(long long val, long long MOD) : MODVALUE(MOD), val((val % MOD + MOD) % MOD) { } }; using Mint = Modular; inline ll binpow(ll b, ll p, ll mod) { b %= mod; ll ans = 1; for (; p > 0; p >>= 1) { if (p&1) {ans *= b; ans %= mod;} b *= b; b %= mod; } return ans; } inline ll max(ll a, int b) { return (a > b ? a : b); } inline ll max(int a, ll b) { return (a > b ? a : b); } inline ll min(ll a, int b) { return (a < b ? a : b); } inline ll min(int a, ll b) { return (a < b ? a : b); } template <class T> inline bool chkmin(T&x, const T& y) { return x > y ? x = y, 1 : 0; } template <class T> inline bool chkmax(T&x, const T& y) { return x < y ? x = y, 1 : 0; } } namespace IO { template<class T> inline void _R(T &x) {cin >> x;} template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);} template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);} template<class T> inline void _R(deque<T> &x) {for (auto& i : x) _R(i);} inline void R() {} template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);} template<class T> inline void _W(const T& x); template<class T1, class T2> inline void _W(const pair<T1,T2>& p); template<class... T> inline void _W(const vector<T...>& x); template<class... T> inline void _W(const deque<T...>& x); template<class... T> inline void _W(const forward_list<T...>& x); template<class... T> inline void _W(const list<T...>& x); template<class... T> inline void _W(const set<T...>& x); template<class... T> inline void _W(const multiset<T...>& x); template<class... T> inline void _W(const unordered_set<T...>& x); template<class... T> inline void _W(const unordered_multiset<T...>& x); template<class... T> inline void _W(const map<T...>& x); template<class... T> inline void _W(const multimap<T...>& x); template<class... T> inline void _W(const unordered_map<T...>& x); template<class... T> inline void _W(const unordered_multimap<T...>& x); template<class T> inline void _W(const ordered_set<T>& x); template<class Container> inline void printContainer(const Container& x) { bool isFirst = 1; for (auto i : x) { if (!isFirst) cout << ' '; isFirst = 0; _W(i); } } template<class T> inline void _W(const T& x) {cout << x;} template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);} template<class... T> inline void _W(const vector<T...>& x) { printContainer(x); } template<class... T> inline void _W(const deque<T...>& x) { printContainer(x); } template<class... T> inline void _W(const forward_list<T...>& x) { printContainer(x); } template<class... T> inline void _W(const list<T...>& x) { printContainer(x); } template<class... T> inline void _W(const set<T...>& x) { printContainer(x); } template<class... T> inline void _W(const multiset<T...>& x) { printContainer(x); } template<class... T> inline void _W(const unordered_set<T...>& x) { printContainer(x); } template<class... T> inline void _W(const unordered_multiset<T...>& x) { printContainer(x); } template<class... T> inline void _W(const map<T...>& x) { printContainer(x); } template<class... T> inline void _W(const multimap<T...>& x) { printContainer(x); } template<class... T> inline void _W(const unordered_map<T...>& x) { printContainer(x); } template<class... T> inline void _W(const unordered_multimap<T...>& x) { printContainer(x); } template<class T> inline void _W(const ordered_set<T>& x) { printContainer(x); } inline void W() {cout << '\n';} template<class T> inline void W(const T &x) {_W(x); W();} template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);} } using namespace IO; namespace outputFormat{ inline string Case(int tc) {return "Case #" + to_string(tc) + ':';} inline string YN(bool b) {return b ? "Yes" : "No";} } using namespace outputFormat; namespace std { template <class T1, class T2> struct hash<pair<T1,T2>> { std::size_t operator()(pair<T1,T2> _) const { return hash<T1>{}(_.first) ^ hash<T2>{}(_.second); } }; } const Mint ZERO = Mint(0, MOD998); int main() { int n,m; R(n,m); vector<int> a(n + 1); for (int i = 1; i <= n; i++) R(a[i]); vector<vector<int>> g(n + 1); for (int i = 0; i < m; i++) { int u,v; R(u,v); g[u].pb(v); } vector<int> dep(n + 1, -1); vector<int> nxt(n + 1, -1); function<void(int)> dfs = [&](int u) { if (dep[u] != -1) return; dep[u] = 0; for (auto& v : g[u]) { dfs(v); if (chkmax(dep[u], dep[v] + 1)) nxt[u] = v; } }; for (int u = 1; u <= n; u++) dfs(u); const int maxDep = *max_element(all(dep)); vector<int> xsum(maxDep + 1, 0); for (int u = 1; u <= n; u++) { xsum[dep[u]] ^= a[u]; } bool win = 0; int st = -1; for (int d = 0; d <= maxDep; d++) if (xsum[d]) { win = 1; st = d; } if (!win) { W("LOSE"); return 0; } int stNode = -1; for (int u = 1; u <= n; u++) { if (dep[u] == st && a[u] ^ xsum[st] < a[u]) { stNode = u; break; } } vector<int> ans = a; ans[stNode] ^= xsum[st]; int p = nxt[stNode]; while (p != -1) { ans[p] ^= xsum[dep[p]]; p = nxt[p]; } W("WIN"); for (int u = 1; u <= n; u++) cout << ans[u] << " \n"[u == n]; return 0; } static auto __init__ = [](){ #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed << setprecision(10); return 42; }();
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 int; template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out << x << " "; } out << "\n"; return out; } template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out + x; } return out; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (auto &x : vec) { in >> x; } return in; } void solve() { int n, m; cin >> n >> m; vector<int> h(n); cin >> h; vector<vector<int>> adj(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u; --v; adj[u].push_back(v); } vector<int> dep(n); vector<vector<int>> at(n); vector<bool> vis(n); function<void(int)> dfs = [&](int u) { vis[u] = 1; for (const auto &v : adj[u]) { if (!vis[v]) dfs(v); dep[u] = max(dep[u], dep[v] + 1); } at[dep[u]].push_back(u); }; for (int i = 0; i < n; i++) if (!vis[i]) dfs(i); int start = -1; for (int i = n - 1; i >= 0; --i) { int xr = 0; for (const auto &u : at[i]) xr ^= h[u]; if (xr == 0) continue; for (const auto &u : at[i]) { if ((xr ^ h[u]) < h[u]) { start = u; } } break; } if (start == -1) { cout << "LOSE\n"; return; } vector<int> ans = h; function<void(int)> findans = [&](int u) { int d = dep[u]; int xr = 0; for (const auto &v : at[d]) { xr ^= h[v]; } ans[u] = xr ^ h[u]; for (const auto &v : adj[u]) { if (dep[v] + 1 == dep[u]) { findans(v); break; } } }; findans(start); cout << "WIN" << "\n"; cout + ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); 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 namespace std; int n, m, h[200005], grundy[200005], in[200005], sum[200005]; vector<int> edge[200005]; bool must[200005]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &h[i]); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; edge[a].push_back(b); in[b]++; } queue<int> que; vector<int> process; for (int i = 0; i < n; i++) if (!in[i]) que.push(i); while (!que.empty()) { int q = que.front(); que.pop(); process.push_back(q); for (int i = 0; i < edge[q].size(); i++) { int to = edge[q][i]; in[to]--; if (in[to] == 0) que.push(to); } } reverse(process.begin(), process.end()); memset(grundy, -1, sizeof(grundy)); for (int i = 0; i < process.size(); i++) { int cur = process[i]; set<int> S; for (int j = 0; j < edge[cur].size(); j++) { int to = edge[cur][j]; S.insert(grundy[to]); } for (int i = 0; i < 200005; i++) if (S.find(i) == S.end()) { grundy[cur] = i; break; } } for (int i = 0; i < n; i++) { if (h[i] % 2 == 1) sum[grundy[i]]++; } vector<int> vec; for (int i = 0; i < 200005; i++) { if (sum[i] % 2 == 1) { vec.push_back(i); must[i] = true; } } if (vec.empty()) { puts("LOSE"); return 0; } else { puts("WIN"); for (int i = 0; i < n; i++) { if (h[i] % 2 == 1 && must[grundy[i]]) { printf("%d ", h[i] - 1); must[grundy[i]] = 0; } else { printf("%d ", h[i]); } } for (int i = 0; i < 200005; i++) assert(must[i] == false); 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 head[400005], ver[400005], nxt[400005], cnt; void add(long long a, long long b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; } vector<long long> e[400005], has[400005]; long long n, m, cd[400005]; long long a[400005], sg[400005]; long long pos[400005], mex[400005], mx; bool vis[400005]; queue<long long> q, ans; int main() { scanf("%d%d", &n, &m); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); for (long long i = 1, a, b; i <= m; i++) { scanf("%d%d", &a, &b); add(a, b), e[b].push_back(a), cd[a]++; } for (long long i = 1; i <= n; i++) if (!cd[i]) q.push(i); while (!q.empty()) { long long now = q.front(); q.pop(), cnt = 0; for (long long i = head[now]; i; i = nxt[i]) mex[++cnt] = pos[ver[i]]; pos[now] = 1; sort(mex + 1, mex + 1 + cnt); for (long long 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 (long long i = 0; i < e[now].size(); i++) { cd[e[now][i]]--; if (!cd[e[now][i]]) q.push(e[now][i]); } } for (long long o = mx; o >= 1; o--) { if (sg[o] != 0) { long long now; for (long long i = 0; i < has[o].size(); i++) { if ((a[has[o][i]] ^ sg[o]) <= a[has[o][i]]) { ans.push(has[o][i]); } } now = ans.front(); if (n == 700 && m == 200000) cout << ans.size(); a[now] ^= sg[o]; for (long long i = head[now]; i; i = nxt[i]) { long long to = ver[i]; if (vis[pos[to]]) continue; vis[pos[to]]; a[to] = sg[pos[to]] ^ a[to]; } printf("WIN\n"); for (long long 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> using namespace std; const int N = 200010; struct Edge { int to, next; } edge[N * 2]; 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; for (int i = head[x]; i; i = edge[i].next) tmp.push_back(dfs(edge[i].to)); sort(tmp.begin(), tmp.end()); if (!tmp.size()) sg[x] = 0; else { for (int i = 0; i <= tmp.size() - 1; i++) if (i != tmp[i]) { sg[x] = i; break; } if (sg[x] == -1) sg[x] = tmp.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; inline int read() { int w = 1, s = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return w * s; } int n, m, h[1001000], Sum[1010010], Sg[1010010], tag[1010010], du[1010010], Seq[1010000], cnt; vector<int> vec[1010100]; queue<int> q; inline void Top_Sort() { for (register int i = 1; i <= n; ++i) if (!du[i]) q.push(i), Seq[++cnt] = i; while (!q.empty()) { int u = q.front(); q.pop(); for (auto x : vec[u]) { du[x]--; if (!du[x]) q.push(x), Seq[++cnt] = x; } } } int main() { n = read(), m = read(); for (register int i = 1; i <= n; ++i) h[i] = read(); for (register int i = 1; i <= m; ++i) { int u = read(), v = read(); vec[u].push_back(v); du[v]++; } Top_Sort(); for (register int i = n; i >= 1; --i) { int u = Seq[i]; for (auto x : vec[u]) { tag[Sg[x]] = i; } while (tag[Sg[u]] == i) Sg[u]++; Sum[Sg[u]] ^= h[u]; } for (register int i = n; i >= 1; --i) { if (Sum[i]) { int xx = 0; for (register int j = 1; j <= n; ++j) if ((Sg[j] == i) && (h[j] > (h[j] ^ Sum[i]))) xx = j; h[xx] = h[xx] ^ Sum[i]; for (auto x : vec[xx]) h[x] = Sum[Sg[x]] ^ h[x], Sum[Sg[x]] = 0; cout << "WIN\n"; for (register int i = 1; i <= n; ++i) cout << h[i] << " "; exit(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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 2e5 + 5; int n, m, id[N], vis[N]; long long h[N], sum[N]; vector<int> E[N]; void dfs(int u) { for (int v : E[u]) if (!id[v]) dfs(v); for (int v : E[u]) vis[id[v]] = 1; for (id[u] = 1; vis[id[u]]; ++id[u]) ; sum[id[u]] ^= h[u]; for (int v : E[u]) vis[id[v]] = 0; } int main() { n = read(), m = read(); for (int i = (1), _ed = (n); i <= _ed; ++i) h[i] = read(); for (int i = (1), _ed = (m); i <= _ed; ++i) E[read()].push_back(read()); for (int i = (1), _ed = (n); i <= _ed; ++i) if (!id[i]) dfs(i); int p = 0; for (int i = (n), _ed = (1); i >= _ed; --i) if (sum[i]) { p = i; break; } if (!p) return puts("LOSE"), 0; else puts("WIN"); int rt = 0; for (int i = (1), _ed = (n); i <= _ed; ++i) { if (id[i] ^ p) continue; if (h[i] > (h[i] ^ sum[p])) { rt = i; break; } } h[rt] = h[rt] ^ sum[p], sum[p] = 0; for (int v : E[rt]) { if (!sum[id[v]]) continue; h[v] = h[v] ^ sum[id[v]], sum[id[v]] = 0; } for (int i = (1), _ed = (n); i <= _ed; ++i) printf("%lld%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> const int N = 200005; int n, m, sg[N]; bool r[N]; long long a[N], sum[N]; std::vector<int> g[N]; bool vis[N]; int dfs(int x) { if (~sg[x]) return sg[x]; for (int p : g[x]) dfs(p); for (int p : g[x]) vis[dfs(p)] = 1; for (int i = 0;; ++i) if (!vis[i]) { sg[x] = i; break; } for (int p : g[x]) vis[dfs(p)] = 0; return sg[x]; } void print(int col) { std::cout << "WIN\n"; int pos = 0; for (int i = 1; i <= n; ++i) if (sg[i] == col && a[i] >= a[pos]) pos = i; a[pos] ^= sum[col], sum[col] = 0; for (int p : g[pos]) a[p] ^= sum[sg[p]], sum[sg[p]] = 0; for (int i = 1; i <= n; ++i) std::cout << a[i] << ' '; std::cout << '\n', std::exit(0); } int main() { std::ios::sync_with_stdio(0), std::cin.tie(0); std::cin >> n >> m; for (int i = 1; i <= n; ++i) std::cin >> a[i], sg[i] = -1; for (int i = 0, x, y; i < m; ++i) std::cin >> x >> y, g[x].emplace_back(y); for (int i = 1; i <= n; ++i) sum[dfs(i)] ^= a[i]; for (int i = n - 1; ~i; --i) if (sum[i]) print(i); std::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; int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return flg ? -x : x; } int n, m, h[200010], g[200010]; vector<int> e[200010]; int d[200010]; int p[200010], hd, tl; int sg[200010]; int get(int o) { static int vis[200010]; for (const int &v : e[o]) vis[sg[v]] = o; int z = 0; while (vis[z] == o) ++z; return z; } void work(int o) { h[o] ^= g[sg[o]]; for (const int &v : e[o]) { if (sg[v] >= sg[o]) continue; int w = g[sg[v]]; h[v] ^= w; g[sg[v]] ^= w; } for (int i(1), _i(n); i <= _i; i++) printf("%d ", h[i]); puts(""); } void solve() { n = read(), m = read(); for (int i(1), _i(n); i <= _i; i++) h[i] = read(); while (m--) { int u = read(), v = read(); e[u].push_back(v), ++d[v]; } for (int i(1), _i(n); i <= _i; i++) if (!d[i]) p[++tl] = i; while (hd < tl) { int u = p[++hd]; for (const int &v : e[u]) if (!--d[v]) p[++tl] = v; } for (int i(n), _i(1); i >= _i; i--) sg[p[i]] = get(p[i]), g[sg[p[i]]] ^= h[p[i]]; int q = -1; for (int i(0), _i(n); i <= _i; i++) if (g[i]) { q = i; break; } if (!~q) return puts("LOSE"), void(); puts("WIN"); for (int i(1), _i(n); i <= _i; i++) if (sg[i] == q && (g[sg[i]] ^ h[i]) < h[i]) { work(i); return; } assert(0); } int main() { for (int T = 1; T--;) 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; 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; } if (n == 700 && m == 200000) cout << now << endl; 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> using namespace std; vector<vector<int>> E; vector<int> G; vector<int> h; void dfs(int cur) { if (G[cur] != -1) return; set<int> S; for (int i = 0; i < (E[cur].size()); ++i) { int to = E[cur][i]; dfs(to); S.insert(G[to]); } for (int i = 0; i < (1000000001); ++i) { if (!(S.count(i))) { G[cur] = i; break; } } } int main() { int n, m; scanf("%d %d", &n, &m); h.resize(n); for (int i = 0; i < (n); ++i) scanf("%d", &h[i]); E.resize(n); G.resize(n, -1); for (int i = 0; i < (m); ++i) { int u, v; scanf("%d %d", &u, &v); u--; v--; E[u].push_back(v); } for (int i = 0; i < (n); ++i) { dfs(i); } vector<int> Gs(1000, 0); for (int i = 0; i < (n); ++i) { Gs[G[i]] ^= h[i]; } for (int i = 999; i >= 0; i--) { if (Gs[i] == 0) continue; int maxi = -1, ind = -1; for (int j = 0; j < (n); ++j) { if (G[j] == i) { if (maxi < h[j]) { maxi = h[j]; ind = j; } } } h[ind] = Gs[i] ^ h[ind]; Gs[i] = 0; for (int j = 0; j < (E[ind].size()); ++j) { int to = E[ind][j]; h[to] = Gs[G[to]] ^ h[to]; Gs[G[to]] = 0; } cout << "WIN" << endl; for (int j = 0; j < (n); ++j) { if (j != 0) printf(" "); printf("%d", 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; #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i) #define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i) typedef long long ll; template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;} template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;} inline int read(){ int x; char c; int f=1; while((c=getchar())!='-' && (c>'9' || c<'0')); if(c=='-') f=-1,c=getchar(); x=c^'0'; while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0'); return x*f; } inline ll readll(){ ll x; char c; int f=1; while((c=getchar())!='-' && (c>'9' || c<'0')); if(c=='-') f=-1,c=getchar(); x=c^'0'; while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0'); return x*f; } const int maxn=2e5+10; vector<int> G[maxn],E[maxn]; int sum[maxn],p[maxn],sg[maxn],d[maxn],a[maxn]; int main(){ int n=read(),m=read(); REP(i,1,n) a[i]=read(); REP(i,1,m){ int x=read(),y=read(); G[y].push_back(x); E[x].push_back(y); ++d[x]; } queue<int> q; REP(i,1,n) if(!d[i]) q.push(i); while(!q.empty()){ int u=q.front();q.pop(); for(int v:E[u]) p[sg[v]]=u; while(p[sg[u]]==u) ++sg[u]; sum[sg[u]]^=a[u]; for(int v:G[u]){ --d[v]; if(!v) q.push(v); } } DREP(_,n-1,0) if(sum[_]){ printf("WIN\n"); REP(i,1,n) if(sg[i]==_ && a[i]>=(sum[sg[i]]^a[i])){ a[i]^=sum[sg[i]]; for(int v:E[i]) a[v]^=sum[sg[v]],sum[sg[v]]=0; break; } REP(i,1,n) printf("%d%c",a[i],i==iend?'\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" ] }
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]; ans[sg[i]] ^= a[i]; } int pd = 0; for (int i = (0); i <= (n); ++i) pd += ans[i], maxx = (ans[i] > 0 ? i : maxx); for (int i = (1); i <= (n); ++i) if (sg[i] == maxx && (ans[maxx] ^ a[i]) < a[i]) { id = i; break; } if (!pd) return puts("LOSE"), 0; assert(id != -1); puts("WIN"); a[id] ^= ans[sg[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; 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++) { 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; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; break; } } if (!f) { puts("LOSE"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (mex[u] == tmp && (a[u] ^ nim[tmp]) < a[u]) { a[u] = nim[mex[u]] ^= a[u]; for (int v : e[u]) { if (nim[mex[v]]) a[v] = nim[mex[v]] ^= a[v]; } 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; 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) { int y = e[i].to; tag[w[y]] = x; if (--d[y] == 0) q.push(y); } 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), (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" ] }
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]; void Add(int i, int j) { tot++; edge[tot].num = j; edge[tot].next = last[i]; last[i] = tot; } void dfs(int i) { used[i] = 1; priority_queue<int, vector<int>, greater<int> > q; for (int k = last[i]; k != 0; k = edge[k].next) { int v = edge[k].num; if (used[v]) q.push(sg[v]); else { dfs(v); q.push(sg[v]); } } int x = 0; while (!q.empty()) { int p = q.top(); q.pop(); if (p < x) continue; if (p == x) x++; else break; } sg[i] = x; } 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) dfs(i); 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; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update> template <typename T> void resize(int n, vector<T> &u) { u.resize(n); } template <typename Head, typename... Tail> void resize(int n, Head &H, Tail&... T) { resize(n, H); resize(n, T...); } template <typename T, typename Head> void to_dimension(T m, Head &u, int n) { u.resize(n, m); } template <typename T> void set_dimension(T &u, int n) { u.resize(n); } template <typename T, typename Head, typename... Tail> void to_dimension(T m, Head &u, int n, Tail... F) { u.resize(n); for(auto &i : u) { to_dimension(m, i, F...); } } template <typename Head, typename... Tail> void set_dimension(Head &u, int n, Tail... F) { u.resize(n); for(auto &i : u) { set_dimension(i, F...); } } template <typename T> void unique(vector<T> &u) { sort(u.begin(), u.end()); u.resize(unique(u.begin(), u.end()) - u.begin()); } template <typename T> void debug_out(T t) { cerr << t; } template <typename A, typename B> void debug_out(pair<A, B> u) { cerr << "(" << u.first << " " << u.second << ")"; } template <typename T> void debug_out(vector<T> t) { int sz = t.size(); for(int i = 0; i < sz; i++) { debug_out(t[i]); if(i != sz - 1) cerr << ", "; } } template <typename T> void debug_out(vector<vector<T>> t) { int sz = t.size(); for(int i = 0; i < sz; i++) { debug_out(t[i]); if(i != sz - 1) cerr << endl; } } template<typename T> T maxest(T a, T b) { return (a > b ? a : b); } template<typename T, typename... Tail> T maxest(T a, T b, Tail... c) { return maxest(maxest(a, b), c...); } template<typename T> T minest(T a, T b) { return (a < b ? a : b); } template<typename T, typename... Tail> T minest(T a, T b, Tail... c) { return minest(minest(a, b), c...); } vector<char> lowchar = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; vector<char> hichar = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; vector<char> base_10 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; vector<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0}; template <typename T> string to_string(T t) { ostringstream ss; ss << t; return ss.str(); } long long to_num(string t) { long long res = 0; for(int i = 0; i < (int) t.length(); i++) { res *= 10; res += t[i] - '0'; } return res; } string to_base(long long n, int base) { string res; while(n) { res += to_string(n % base); n /= base; } reverse(res.begin(), res.end()); return res; } inline int next_bit_perm(int v) { int t = v | (v - 1); return (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1)); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl; #define range(i, m, n) for(int i = m; i < n; i++) #define husk(i, m, n) for(int i = m; i > n; i--) #define sub_mask(i, mask) for(int i = mask; ~i; i = (i == 0 ? -1 : (i - 1) & mask)) #define card_mask(i, n) for(int k = 1; k <= n; k++) for(int i = (1 << k) - 1; i < (1 << n); i = next_bit_perm(i)) int n, m; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; vector<vector<int>> edges(n); vector<int> h(n); range(i, 0, n) { cin >> h[i]; } range(i, 0, m) { int a, b; cin >> a >> b; a--; b--; edges[a].push_back(b); } vector<int> mex(n, -1); function<void(int)> dfs = [&] (int v) { if(~mex[v]) return; int res = 0; unordered_set<int> cur; for(auto i : edges[v]) { dfs(i); cur.insert(mex[i]); } while(cur.find(res) != cur.end()) res++; mex[v] = res; }; range(i, 0, n) { if(mex[i] == -1) dfs(i); } vector<int> total(n); range(i, 0, n) { total[mex[i]] ^= h[i]; } if(*max_element(total.begin(), total.end()) == 0) { cout << "LOSE"; return 0; } cout << "WIN\n"; husk(id, n - 1, -1) { if(total[id]) { int z = 31 - __builtin_clz(total[id]); range(i, 0, n) { if(mex[i] == id && h[i] & (1 << z)) { h[i] ^= total[id]; assert(h[i] < h[i] ^ total[id]); for(auto j : edges[i]) { h[j] ^= total[mex[j]]; } break; } } break; } } for(auto i : h) cout << 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> const int N = 200005; int n, m, t = -1, he, ta, sg[N], d[N], s[N], q[N]; bool vis[N]; long long h[N]; struct ed { ed* nxt; int to; } pool[N], *p = pool, *lnk[N]; void ae(int u, int v) { *++p = (ed){lnk[u], v}, ++d[v], lnk[u] = p; } void dfs(int u) {} 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); ae(u, v); } for (int i = (1); i <= (n); ++i) if (!d[i]) q[++ta] = i; while (he != ta) { int u = q[++he]; for (ed* i = lnk[u]; i; i = i->nxt) if (!--d[i->to]) q[++ta] = i->to; } for (int i = (n); i >= (1); --i) { int u = q[i]; for (ed* i = lnk[u]; i; i = i->nxt) vis[sg[i->to]] = 1; while (vis[sg[u]]) ++sg[u]; for (ed* i = lnk[u]; i; i = i->nxt) vis[sg[i->to]] = 0; s[sg[u]] ^= h[u]; } for (int i = (1); i <= (n); ++i) if (s[i]) t = i; if (t == -1) return 0 & puts("LOSE"); for (int i = (1); i <= (n); ++i) { if (sg[i] == t && ((h[i] ^ s[t]) < h[i])) { h[i] ^= s[t]; for (ed* j = lnk[i]; j; j = j->nxt) { h[j->to] ^= s[sg[j->to]]; s[sg[j->to]] = 0; } break; } } puts("WIN"); 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; for (int i = head[x]; i; i = edge[i].next) tmp.push_back(dfs(edge[i].to)); sort(tmp.begin(), tmp.end()); if (!tmp.size()) sg[x] = 0; else { if (tmp[0] != 0) sg[x] = 0; else { for (int i = 1; i <= tmp.size() - 1; i++) if (tmp[i] - tmp[i - 1] > 1) { sg[x] = tmp[i - 1] + 1; break; } if (sg[x] == -1) sg[x] = tmp.back() + 1; } } 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]; printf("%d %d\n", i, sg[i]); } bool flag = false; for (int i = 0; i <= n; i++) if (sh[i]) flag = true; if (flag) { printf("WIN\n"); int tmp = -1, mx = 0; for (int i = 1; i <= n; i++) { if (tmp == -1 || (sg[tmp] <= sg[i] && (h[i] ^ sh[sg[i]]) <= h[i])) tmp = i; mx = max(mx, sg[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> 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 >= 0 && !B[cur]) --cur; if (cur < 0) 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> using namespace std; long long n, m, num[200100], sy[200100], ds[200100], bj[200100], sum[200100]; vector<long long> to[200100], pre[200100]; queue<long long> que; int main() { long long i, j, t, p, q; cin >> 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); for (; !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]]) 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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e5 + 5; int n, m; int h[N]; int ans[N]; struct Edge { int num; int next; } edge[M]; int tot, last[N]; int du[N]; int sg[N]; bool used[N]; void Add(int i, int j) { tot++; edge[tot].num = j; edge[tot].next = last[i]; last[i] = tot; } void dfs(int i) { used[i] = 1; priority_queue<int, vector<int>, greater<int> > q; for (int k = last[i]; k != 0; k = edge[k].next) { int v = edge[k].num; if (used[v]) q.push(sg[v]); else { dfs(v); q.push(sg[v]); } } int x = 0; while (!q.empty()) { int p = q.top(); q.pop(); if (p < x) continue; if (p == x) x++; else break; } sg[i] = x; } 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); Add(u, v); du[v]++; } for (int i = 1; i <= n; i++) if (du[i] == 0) dfs(i); 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("%d ", 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 = 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] = 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> 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 = 31; 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 && get_high(h[i]) == get_high(sum[mx])) pos = i; 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; 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]; 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
#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++) { 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; } bool f = 0; int tmp = 0; for (int i = n; i; i--) { if (nim[i]) { f = 1; tmp = i; break; } } if (!f) { puts("LOSE"); return 0; } puts("WIN"); for (int u = 1; u <= n; u++) { if (mex[u] == tmp && a[u] ^ nim[mex[u]] < a[u]) { 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; 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 u = 1; u <= n; u++) cout << h[u] << ' '; 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 maxn = 2e5 + 5; int n, m; int h[maxn], in[maxn], q[maxn], sg[maxn], sum[maxn], vis[maxn]; vector<int> G[maxn]; 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); G[u].push_back(v); ++in[v]; } int l = 1, r = 0; for (int i = 1; i <= n; ++i) if (!in[i]) q[++r] = i; while (l <= r) { int u = q[l++]; for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if (!--in[v]) q[++r] = v; } } for (int i = n; i; --i) { int u = q[i]; for (int j = 0; j < G[u].size(); ++j) { int v = G[u][j]; vis[sg[v]] = 1; } for (; vis[sg[u]]; ++sg[u]) ; for (int j = 0; j < G[u].size(); ++j) { int v = G[u][j]; vis[sg[v]] = 0; } } for (int i = 1; i <= n; ++i) sum[sg[i]] ^= h[i]; int p = -1; for (int i = n; ~i; --i) if (sum[i]) { p = i; break; } if (p == -1) { puts("LOSE"); return 0; } puts("WIN"); for (int i = 1; i <= n; ++i) if (sg[i] == p) { if ((sum[p] ^ h[i]) > h[i]) continue; h[i] ^= sum[p]; for (int j = 0; j < G[i].size(); ++j) { int v = G[i][j]; h[v] ^= sum[sg[v]]; sum[sg[v]] = 0; } } 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> #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]; void d1(int v){ leafd[v] = 0; FORR(i,adj[v]){ /* d1(i); */ if(leafd[i] == -1){ d1(i); } leafd[v] = max(leafd[v], leafd[i] + 1); } xr[leafd[v]] ^= a[v]; } void d2(int v){ resa[v] = a[v] ^ xr[leafd[v]]; if(leafd[v] == 0) return; pi mx = {-1,-1}; FORR(i,adj[v]){ 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; } } d2(tp); FOR(i,0,n){ cout << resa[i] << ' '; } 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
#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; rep(i, n + 1){ if(grundy2[grundy[i]]){ lose = 0; } } if(lose){ cout<<"LOSE\n"; return; } cout<<"WIN\n"; for(int i = 0; i < n; i++){ 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 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 = 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 n, m; vector<int> a[200005]; struct edge { int to, nxt; } e[200005]; int hed[200005], cnt; inline void add(int u, int v) { e[++cnt] = (edge){v, hed[u]}; hed[u] = cnt; } int num[200005], ru[200005]; int sg[200005], tag[200005], dep[200005]; inline void topo() { queue<int> q; for (int i = 1; i <= n; ++i) if (!ru[i]) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < a[u].size(); ++i) tag[dep[a[u][i]]] = u; while (tag[dep[u]] == u) dep[u]++; sg[dep[u]] ^= num[u]; for (int i = hed[u]; i; i = e[i].nxt) { int v = e[i].to; if (--ru[v] == 0) q.push(v); } } } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", num + i); int u, v; for (int i = 1; i <= m; ++i) { scanf("%d%d", &u, &v); a[u].push_back(v), add(v, u), ru[u]++; } topo(); for (int i = n; i >= 0; --i) { if (sg[i] == 0) continue; for (int j = 1; j <= n; ++j) { if (dep[j] == i && num[j] > (num[j] ^ sg[i])) { u = j; break; } } num[u] ^= sg[i]; for (int j = 0; j < a[u].size(); ++j) { int v = a[u][j]; num[v] ^= sg[dep[u]], sg[dep[u]] = 0; } printf("WIN\n"); for (int j = 1; j <= n; ++j) printf("%d ", num[j]); return 0; } printf("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 = 200005; int ver[N << 1], nxt[N << 1], head[N], deg[N], tot; int h[N], st[N], vis[N << 1], id[N], t[N << 1], Max, top, n, m; queue<int> q; vector<int> v[N]; inline int read() { int 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(int x, int y) { ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; deg[y]++; } int main() { n = read(); m = read(); for (int i = 1; i <= n; i++) h[i] = read(); for (int i = 1; i <= m; i++) { int u, v; u = read(); v = read(); add(u, v); } for (int i = 1; i <= n; i++) if (!deg[i]) q.push(i); while (q.size()) { int x = q.front(); q.pop(); st[++top] = x; for (int i = head[x]; i; i = nxt[i]) { int y = ver[i]; v[x].push_back(y); deg[y]--; if (!deg[y]) q.push(y); } } for (int i = top; i >= 1; i--) { for (int j = head[i]; j; j = nxt[j]) vis[id[ver[j]]] = 1; for (int nw = 0;; nw++) { if (!vis[nw]) { id[i] = nw; break; } } t[id[i]] ^= h[i]; Max = max(Max, id[i]); for (int j = head[i]; j; j = nxt[j]) vis[id[ver[j]]] = 0; } int flag = 0; for (int i = 0; i <= Max; i++) { if (t[i]) { flag = 1; break; } } if (!flag) { puts("LOSE"); return 0; } for (int i = 1; i <= n; i++) { if (!t[id[i]]) continue; for (int j = head[i]; j; j = nxt[j]) { int y = ver[j]; if (id[y] < id[i] && t[id[y]]) { h[y] ^= t[id[y]]; } } } 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; long long head[400005], ver[400005], nxt[400005], cnt; void add(long long a, long long b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; } vector<long long> e[400005], has[400005]; long long n, m, cd[400005]; long long a[400005], sg[400005]; long long pos[400005], mex[400005], mx; bool vis[400005]; queue<long long> q; int main() { scanf("%d%d", &n, &m); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); for (long long i = 1, a, b; i <= m; i++) { scanf("%d%d", &a, &b); add(a, b), e[b].push_back(a), cd[a]++; } for (long long i = 1; i <= n; i++) if (!cd[i]) q.push(i); while (!q.empty()) { long long now = q.front(); q.pop(), cnt = 0; for (long long i = head[now]; i; i = nxt[i]) mex[++cnt] = pos[ver[i]]; pos[now] = 1; sort(mex + 1, mex + 1 + cnt); for (long long 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 (long long i = 0; i < e[now].size(); i++) { cd[e[now][i]]--; if (!cd[e[now][i]]) q.push(e[now][i]); } } for (long long o = mx; o >= 1; o--) { if (sg[o] != 0) { long long now; for (long long 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 (long long i = head[now]; i; i = nxt[i]) { long long to = ver[i]; if (vis[pos[to]]) continue; vis[pos[to]]; a[to] = sg[pos[to]] ^ a[to]; } printf("WIN\n"); for (long long 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> using namespace std; int n, m, h[200000 + 5], head[200000 + 5], cnt, val[200000 + 5], maxv, w[705]; struct edge { int to, next; } e[200000 + 5]; void dfs(int x) { if (val[x] != -1) return; bool sf[705] = {0}; for (int i = head[x]; i; i = e[i].next) dfs(e[i].to), sf[val[e[i].to]] = 1; for (val[x] = 0; sf[val[x]]; ++val[x]) ; maxv = max(maxv, val[x]), w[val[x]] ^= h[x]; } int main() { memset(val, -1, sizeof val); 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), e[++cnt] = (edge){v, head[u]}, head[u] = cnt; for (int i = 1; i <= n; ++i) dfs(i); for (int p = maxv; p >= 0; --p) if (w[p]) { puts("WIN"); for (int x = 1; x <= n; ++x) if ((h[x] ^ w[p]) < w[p]) { h[x] ^= w[p]; for (int i = head[x]; i; i = e[i].next) h[e[i].to] ^= w[val[e[i].to]], w[val[e[i].to]] = 0; for (int i = 1; i <= n; ++i) printf("%d ", h[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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, h[200005]; int info[200005], Prev[200005], to[200005], cnt_e; void Node(int u, int v) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v; } int in[200005], Q[200005], L, R, SG[200005], S[200005]; int vis[200005], 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 = n - 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 <= Mx; 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
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::set; using std::vector; const int MAX_N = 2e5 + 10; int N, M, lvl[MAX_N]; vector<int> succ[MAX_N]; long long H[MAX_N]; long long sLvl[MAX_N]; bool done[MAX_N]; int getLvl(int x) { if (lvl[x] != -1) return lvl[x]; set<int> st; for (auto i : succ[x]) st.insert(getLvl(i)); for (lvl[x] = 0; st.count(lvl[x]); lvl[x]++) ; return lvl[x]; } int main() { cin >> N >> M; for (int i = 1; i <= N; i++) cin >> H[i]; for (int i = 1; i <= M; i++) { int u, v; cin >> u >> v; succ[u].push_back(v); } for (int i = 1; i <= N; i++) lvl[i] = -1; for (int i = 1; i <= N; i++) getLvl(i); for (int i = 1; i <= N; i++) sLvl[lvl[i]] ^= H[i]; int mxl = -1; for (int i = 0; i <= N; i++) if (sLvl[i]) mxl = i; if (mxl == -1) cout << "LOSE" << endl; else { int sel = 0; for (int i = 1; i <= N; i++) if (lvl[i] == mxl && (H[i] & sLvl[mxl]) > (H[sel] & sLvl[mxl])) sel = i; H[sel] ^= sLvl[mxl]; for (auto i : succ[sel]) { if (done[lvl[i]]) continue; H[i] ^= sLvl[lvl[i]]; } cout << "WIN" << endl; for (int i = 1; i <= N; i++) cout << H[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
#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"); if((H[i] ^ grundy2[grundy[i]]) >= H[i]){ H[i] ^= grundy2[grundy[i]]; grundy2[grundy[i]] = 0; } // H[i] ^= grundy2[grundy[i]]; // grundy2[grundy[i]] = 0; } cout<<H[i]<<" "; } cout<<endl; // cout<<(394273396 ^ 395063145 ^ 789789)<<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 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 && sghigh ^ h[i] < h[i]) { h[i] = sghigh ^ h[i]; for (int j = 0; j < G[i].size(); ++j) { int c = G[i][j]; h[c] ^= XOR[sg[c]]; } 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; #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[w[i]] != 0) { win = true; if (mx == -1 || w[mx] < w[i] || w[mx] == w[i] && h[mx] < h[i]) mx = i; } } if (win) { cout << "WIN\n"; for (int to : g[mx]) { if (s[w[to]] != 0) { h[to] = s[w[to]] ^ h[to]; s[w[to]] = 0; } } h[mx] = s[w[mx]] ^ h[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; 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 (w == -1 || h[i] > h[w]) w = i; } 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; inline int read() { int w = 1, s = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return w * s; } int n, m, h[1001000], Sum[1010010], Sg[1010010], tag[1010010], du[1010010], Seq[1010000], cnt; vector<int> vec[1010100]; queue<int> q; inline void Top_Sort() { for (register int i = 1; i <= n; ++i) if (!du[i]) q.push(i), Seq[++cnt] = i; while (!q.empty()) { int u = q.front(); q.pop(); for (auto x : vec[u]) { du[x]--; if (!du[x]) q.push(x), Seq[++cnt] = x; } } } int main() { n = read(), m = read(); for (register int i = 1; i <= n; ++i) h[i] = read(); for (register int i = 1; i <= m; ++i) { int u = read(), v = read(); vec[u].push_back(v); du[v]++; } Top_Sort(); for (register int i = n; i >= 1; --i) { int u = Seq[i]; for (auto x : vec[u]) { tag[Sg[x]] = i; } while (tag[Sg[u]] == i) Sg[u]++; Sum[Sg[u]] ^= h[u]; } for (register int i = n; i >= 1; --i) { if (Sum[i]) { int xx = 0; for (register int j = 1; j <= n; ++j) if ((Sg[j] == i) && (h[j] > (h[j] ^ Sum[i]))) xx = j; h[xx] = h[xx] ^ Sum[i]; for (auto x : vec[xx]) h[x] = Sum[Sg[x]] ^ h[x], Sum[Sg[x]] = 0; cout << "Win\n"; for (register int i = 1; i <= n; ++i) cout << h[i] << " "; exit(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" ] }
IN-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[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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int num[222222], sum[222222], degree[222222], dinv[222222]; vector<int> e[222222], inve[222222]; int q[222222], top, front, isused[222222], bel[222222]; vector<int> v[222222]; int main() { int n, m, a, b; scanf("%d%d", &n, &m); for (int i = 1; i < n + 1; i++) scanf("%d", &num[i]); for (int i = 1; i < m + 1; i++) { scanf("%d%d", &a, &b); inve[b].push_back(a), e[a].push_back(b); degree[a]++, dinv[b]++; } for (int i = 1; i < n + 1; i++) if (!dinv[i]) q[top++] = i; while (top != front) { int k = q[front++]; for (int x : inve[k]) { dinv[x]--; if (!dinv[x]) q[top++] = x; } for (int x : e[k]) isused[x] = k; int now = 0; while (isused[now] == k) now++; sum[now] ^= num[k]; v[now].push_back(k), bel[k] = now; } bool flag = 0; for (int i = 0; i < n + 1; i++) if (sum[i]) { flag = 1; break; } if (flag) { printf("WIN\n"); int x; for (int i = n; i >= 0; i--) if (sum[i]) { x = i; break; } for (int kk : v[x]) { if ((sum[x] ^ num[kk]) < num[kk]) { num[kk] = sum[x] ^ num[kk]; for (int j : e[kk]) if (sum[bel[j]]) num[j] = sum[bel[j]] ^ num[j], sum[bel[j]] = 0; break; } } for (int i = 1; i < n + 1; i++) printf("%d%c", num[i], " \n"[i == n]); } else printf("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; vector<vector<int> > adj(200001); int c[200001], mex[200001], h[200001], b[200001]; void DFS(int i) { if (mex[i] >= 0) { return; } vector<int> v; for (int j : adj[i]) { DFS(j); v.push_back(mex[j]); } for (int x : v) { c[x] = 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) { DFS(i); } int root = 0; mex[root] = -1; for (int i = 1; i <= n; ++i) { b[mex[i]] ^= h[i]; if (mex[i] > mex[root]) { 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" ] }
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 (id >= 0 and tot[id] == 0) id--; if (id < 0 == 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 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) { sg[x] ^= sum[sg[x]]; }; flip(k); vector<int> mark(n + 1, 0); for (int v : G[k]) if (!mark[sg[v]]) flip(v); } for (register int k = 1; k <= (n); k++) cout << sg[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> using namespace std; using ll = long long; constexpr int kMaxN = 2e5 + 3; vector<int> edges[kMaxN]; bitset<kMaxN> visited; int nim[kMaxN]; int mext[kMaxN]; int levels[kMaxN]; vector<int> nim_nodes[kMaxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> h(n); for (int i = 0; i < n; ++i) { cin >> h[i]; } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; edges[u].emplace_back(v); } memset(mext, -1, sizeof(mext)); function<void(int)> dfs = [&](int u) { if (visited[u]) { return; } visited[u] = true; for (int v : edges[u]) { dfs(v); mext[nim[v]] = u; } int k = 0; while (mext[k] == u) { ++k; } nim[u] = k; levels[k] ^= h[u]; nim_nodes[k].emplace_back(u); }; for (int i = 0; i < n; ++i) { dfs(i); } if (count(levels, levels + kMaxN, 0) == kMaxN) { cout << "LOSE\n"; return 0; } cout << "WIN\n"; int last_level = n + 1; while (levels[last_level] == 0) { --last_level; } assert(last_level >= 0); int node = -1; for (int u : nim_nodes[last_level]) { if (h[u] ^ levels[nim[u]] <= h[u]) { h[u] ^= levels[nim[u]]; node = u; levels[nim[u]] = 0; break; } } assert(node != -1); for (int v : edges[node]) { h[v] ^= levels[nim[v]]; levels[nim[v]] = 0; } assert(count(levels, levels + kMaxN, 0) == kMaxN); for (int i = 0; i < n; ++i) { cout << h[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> #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(){ 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; } } } 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> 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 = n - 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
#include <bits/stdc++.h> using namespace std; int n, m, h[200005]; int info[200005], Prev[200005], to[200005], cnt_e; void Node(int u, int v) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v; } int in[200005], Q[200005], L, R, SG[200005], S[200005]; int vis[200005], 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 = n - 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 <= Mx; i++) if (S[i] != 0) flg = 1; if (!flg) puts("LOSE"); else { puts("WIN"); int loc = 0, Max = 0, Maxloc; for (int i = 0; i <= Mx; 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
#include <bits/stdc++.h> using namespace std; int mod = 998244353; int sum(int a, int b) { int c = a + b; if (c >= mod) { c -= mod; } return c; } int dif(int a, int b) { int c = a - b; if (c < 0) { c += mod; } return c; } int mlt(int a, int b) { long long c = a * 1LL * b; return c % mod; } int ibit(int n, int i) { return ((n >> i) & 1); } void outp1(vector<long long> &ou, string s = " ") { cerr << s << endl; for (int i = 0; i < ou.size(); i++) { cerr << ou[i] << ' '; } cerr << endl; } void outp1(vector<int> &ou, string s = " ") { cerr << s << endl; for (int i = 0; i < ou.size(); i++) { cerr << ou[i] << ' '; } cerr << endl; } void outp2(vector<vector<int>> &ou, string s = " ") { cerr << s << endl; for (int i = 0; i < ou.size(); i++) { for (int j = 0; j < ou[i].size(); j++) { cerr << ou[i][j] << ' '; } cerr << '\n'; } } int bp(int x, int y) { if (y == 0) { return 1; } int a = 0; if (!(y % 2)) { a = bp(x, y / 2); } return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a); } int obr(int x) { return bp(x, mod - 2); } const int maxn = 301; int fact[maxn], ofact[maxn]; void prec() { fact[0] = 1; ofact[0] = 1; for (int i = 1; i < maxn; i++) { fact[i] = mlt(fact[i - 1], i); } ofact[maxn - 1] = obr(fact[maxn - 1]); for (int i = maxn - 2; i > 0; i--) { ofact[i] = mlt(ofact[i + 1], i + 1); } } int c(int a, int b) { return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0; } int inf = 1e9 + 110; void reverse(vector<vector<int>> &v, vector<int> &sign, long long &sumx, long long &sumy, int pos, vector<int> &init) { if (sumx <= 1e6 + 1 && sumx >= -1e6 - 2) if (sumy <= 1e6 + 1 && sumy >= -1e6 - 2) { vector<int> reals(v.size()); for (int i = 0; i < v.size(); i++) { reals[v[i][2]] = sign[i]; } for (int i = 0; i < v.size(); i++) cout << reals[i] * init[i] << ' '; cout << '\n'; exit(0); } if (sign[pos] == 1) { sign[pos] = -1; sumx -= 2 * v[pos][0]; sumy -= 2 * v[pos][1]; } else { sign[pos] = 1; sumx += 2 * v[pos][0]; sumy += 2 * v[pos][1]; } if (sumx <= 1e6 + 2 && sumx >= -1e6 - 2) if (sumy <= 1e6 + 2 && sumy >= -1e6 - 2) { vector<int> reals(v.size()); for (int i = 0; i < v.size(); i++) { reals[v[i][2]] = sign[i]; } for (int i = 0; i < v.size(); i++) cout << reals[i] * init[i] << ' '; cout << '\n'; exit(0); } } int mexx(vector<int> &v) { vector<int> u(v.size() + 2); for (auto it : v) { if (it < u.size()) u[it] = 1; } for (int i = 0; i < u.size(); i++) if (u[i] == 0) return i; } void solve(istream &cin = std::cin, ostream &cout = std::cout) { int n, m; cin >> n >> m; vector<vector<int>> gr(n), revgr(n); vector<int> grundy(n, -1), degs(n); vector<long long> vals(n); for (int i = 0; i < n; i++) cin >> vals[i]; set<int> zerodeg; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; degs[x]++; gr[x].push_back(y); revgr[y].push_back(x); } for (int i = 0; i < n; i++) if (!degs[i]) zerodeg.insert(i); while (!zerodeg.empty()) { int a = *zerodeg.begin(); vector<int> v; for (auto g : gr[a]) v.push_back(grundy[g]); grundy[a] = mexx(v); for (auto g : revgr[a]) { degs[g]--; if (degs[g] == 0) zerodeg.insert(g); } zerodeg.erase(a); } vector<int> xors(n + 1); vector<vector<int>> verts(n + 1); for (int i = 0; i < n; i++) { xors[grundy[i]] ^= vals[i]; verts[grundy[i]].push_back(i); } int pos = -1; for (int i = n; i >= 0; i--) if (xors[i] != 0) { pos = i; break; } if (pos == -1) cout << "LOSE" << '\n'; else { int p1 = -1; for (auto ver : verts[pos]) { long long need = vals[ver] ^ xors[pos]; if (need < vals[ver]) { p1 = ver; break; } } assert(p1 != -1); cout << "YES" << '\n'; vals[p1] = vals[p1] ^ xors[pos]; for (auto ver : gr[p1]) { int cal = grundy[ver]; vals[ver] = xors[cal] ^ vals[ver]; xors[cal] = 0; } for (auto it : vals) cout << it << ' '; cout << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int tests = 1; for (int i = 0; i < tests; 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" ] }
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], xo2[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"); bool boo = false; for (int i = (1); i <= (int)(n); ++i) { if (mex[i] != t || (xo[t] ^ H[i]) >= H[i]) { continue; } boo = true; 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; } assert(boo); for (int i = (1); i <= (int)(n); ++i) { printf("%d ", H[i]); xo2[mex[i]] ^= H[i]; } for (int i = (0); i <= (int)(n); ++i) { assert(xo2[i] == 0); } 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; const int N = 200100; int a[N], q[N], n, sum[N], m, d[N], vis[N], sg[N]; vector<int> g[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; g[x].push_back(y); ++d[y]; } int t = 1, w = 0; for (int i = 1; i <= n; ++i) if (!d[i]) q[++w] = i; while (t < w) { int x = q[++t]; for (int i : g[x]) if (!--d[i]) q[++w] = i; } for (int i = n; i; --i) { int x = q[i]; for (int j : g[x]) vis[sg[j]] = i; for (sg[x] = 0; vis[sg[x]] == i; ++sg[x]) ; sum[sg[x]] ^= a[x]; } for (int i = n; i >= 0; --i) if (sum[i]) { cout << "WIN\n"; for (int j = n; j; --j) if (sg[j] == i && a[j] > (sum[i] ^ a[j])) { a[j] ^= sum[i]; for (int k : g[j]) a[k] ^= sum[sg[k]], sum[sg[k]] = 0; for (int k = 1; k <= n; ++k) cout << a[k] << " \n"[i == 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" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int MAXN = 200010; long long head[MAXN], nxt[MAXN], to[MAXN], ind[MAXN], tot; void adde(long long b, long long e) { nxt[++tot] = head[b]; to[head[b] = tot] = e; ++ind[e]; } long long A[MAXN], mx[MAXN]; std::set<long long> S; long long n, m; std::queue<long long> q; long long bfn[MAXN], idx; long long B[MAXN]; signed main() { std::ios_base::sync_with_stdio(false), std::cin.tie(0); std::cin >> n >> m; for (long long i = 1; i <= n; ++i) std::cin >> A[i]; for (long long i = 1, b, e; i <= m; ++i) std::cin >> b >> e, adde(b, e); for (long long i = 1; i <= n; ++i) if (!ind[i]) q.push(i); while (!q.empty()) { long long t = q.front(); q.pop(); bfn[++idx] = t; for (long long i = head[t]; i; i = nxt[i]) if (!--ind[to[i]]) q.push(to[i]); } for (long long T = idx; T; --T) { const long long u = bfn[T]; for (long long 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]; } long long cur = n; while (cur >= 0 && !B[cur]) --cur; if (cur < 0) return std::cout << "LOSE" << std::endl, 0; for (long long 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 (long long 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 (long long 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> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = v * 10 + c - '0'; while (isdigit(c = getchar())) v = v * 10 + c - '0'; x = v * f; } inline void read(long long &x) { long long v = 0ll, f = 1ll; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = v * 10 + c - '0'; while (isdigit(c = getchar())) v = v * 10 + c - '0'; x = v * f; } inline void readc(char &x) { char c; while ((c = getchar()) == ' ') ; x = c; } inline void writes(string s) { puts(s.c_str()); } inline void writeln() { writes(""); } inline void writei(int x) { if (x < 0) { putchar('-'); x = abs(x); } if (!x) putchar('0'); char a[25]; int top = 0; while (x) { a[++top] = (x % 10) + '0'; x /= 10; } while (top) { putchar(a[top]); top--; } } inline void writell(long long x) { if (x < 0) { putchar('-'); x = abs(x); } if (!x) putchar('0'); char a[25]; int top = 0; while (x) { a[++top] = (x % 10) + '0'; x /= 10; } while (top) { putchar(a[top]); top--; } } int n, m, i, j, a[200005], f[200005], s[200005], vis[200005], ti, mx; vector<int> e[200005]; int dfs(int x); void mex(int x) { for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) dfs(*it); ti++; for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) vis[dfs(*it)] = ti; for (f[x] = 0; vis[f[x]] == ti; f[x]++) ; } int dfs(int x) { if (f[x] != -1) return f[x]; mex(x); return f[x]; } void solve(int x) { a[x] ^= s[mx]; s[mx] = 0; for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) { a[*it] ^= s[f[*it]]; s[f[*it]] = 0; } for (((i)) = (1); ((i)) <= ((n)); ((i))++) printf("%d ", a[i]); } int main() { read(n); read(m); for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]); for (((i)) = (1); ((i)) <= ((m)); ((i))++) { int x, y; read(x); read(y); e[x].push_back(y); } memset(f, -1, sizeof(f)); for (((i)) = (1); ((i)) <= ((n)); ((i))++) { mx = max(mx, dfs(i)); s[dfs(i)] ^= a[i]; } while (mx >= 0) { puts("WIN"); for (((i)) = (1); ((i)) <= ((n)); ((i))++) if (f[i] == mx && (s[mx] ^ a[i]) < a[i]) { solve(i); return 0; } mx--; } { cout << "LOSE"; return 0; } return 0; }