chen_zhe_Aya

5134

RyanMoriarty
GhostinLCL
1746705086
Infmelon
Aaron_luomiao

SUPERDOGE
yam
BigJoker
QWQ___Ralph

greater
lzy2008214
zrq071211
werasdxcv345

KK_St
Suzt_Automution

# Enjoy Coding!

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int X;
const int N = 1000010;
inline int Get()
{
scanf ("%d", &X);
return X;
}

struct node
{
int x, y, op;
} que[N];
int a[N];
int fa[N];

inline int find(int x)
{
return x == fa[x] ? x : fa[x] = find(fa[x]);
}

inline void Union(int x, int y)
{
int tx = find(x);
int ty = find(y);
if (tx != ty)
fa[ty] = tx;
}

void work()
{
int tot = 0;
int n = Get();
for (int i = 1; i <= n; i ++)
a[++ tot] = que[i].x = Get(), a[++ tot] = que[i].y = Get(), a[++ tot] = que[i].op = Get();
sort (a + 1, a + tot + 1);
int m = unique(a + 1, a + tot + 1) - a - 1;
for (int i = 1; i <= n; i ++)
{
que[i].x = lower_bound(a + 1, a + m + 1, que[i].x) - a;
que[i].y = lower_bound(a + 1, a + m + 1, que[i].y) - a;
}
for (int i = 1; i <= m; i ++)
fa[i] = i;
for (int i = 1; i <= n; i ++)
if (que[i].op == 1)
Union(que[i].x, que[i].y);
for (int i = 1; i <= n; i ++)
if (que[i].op == 0 && find(que[i].x) == find(que[i].y))
{
puts("NO");
return ;
}
puts("YES");
}

int main()
{
// 能鸽善鹉
int T;
cin >> T;
while (T --)
work();
return 0;
}



NB

## $\mathcal{SOL}$

• 看到这个题脑子嗡了一下。
• 请看后面。

#include <bits/stdc++.h>
#define I_AKIOI ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int p[1000010];
int v[1000010], w[1000010];
int dp[1000010];

namespace IAKIOI
{
int find(int x)  // 并查集
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
void main()
{
I_AKIOI;
int n, m;
cin >> n >> m;
int vol;
cin >> vol;
for (int i = 1; i <= n; i ++)
p[i] = i;
for (int i = 1; i <= n; i ++)
cin >> v[i] >> w[i];
while (m --)
{
int a, b;
cin >> a >> b;
int pa = find(a), pb = find(b);
if (pa != pb)
{
v[pb] += v[pa];
w[pb] += w[pa];
p[pa] = pb;
}
}
for (int i = 1; i <= n; i ++)
if (p[i] == i)
for (int j = vol; j >= v[i]; j --)
dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
cout << dp[vol];
exit(0);
}
}

signed main()
{
IAKIOI::main();
}



## $\mathcal{SOL}$

• 看到这个题脑子嗡了一下。

• 请看后面。

#include <bits/stdc++.h>
using namespace std;

const int N = 40010;
int n, m;
int p[N];

inline int find(int x)
{
return p[x] == x ? x : p[x] = find(p[x]);
}

inline int Get(int x, int y)
{
return x * n + y;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n * n; i ++)
p[i] = i;
long long res = 0;
for (int i = 1; i <= m; i ++)
{
int a, b;
char d;
cin >> a >> b >> d;
int x = a, y = b;
x --;
y --;
a = Get(x, y);
if (d == 'D')
b = Get(x + 1, y);
else
b = Get(x, y + 1);
int pa = find(a);
int pb = find(b);
if (pa == pb)
{
res = i;
break;
}
p[pa] = pb;
}
if (res)
cout << res;
else
cout << "draw";
return 0;
}



@yxc

## $\mathcal{SOL}$

• 看到这个题脑子嗡了一下。
• 请看后面。

#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 9, M = 1 << N;

int ones[M], map[M];
int row[N], col[N], cell[3][3];
char str[100];

void init()
{
for (int i = 0; i < N; i ++ )
row[i] = col[i] = (1 << N) - 1;

for (int i = 0; i < 3; i ++ )
for (int j = 0; j < 3; j ++ )
cell[i][j] = (1 << N) - 1;
}

void draw(int x, int y, int t, bool is_set)
{
if (is_set) str[x * N + y] = '1' + t;
else str[x * N + y] = '.';

int v = 1 << t;
if (!is_set) v = -v;

row[x] -= v;
col[y] -= v;
cell[x / 3][y / 3] -= v;
}

int lowbit(int x)
{
return x & -x;
}

int get(int x, int y)
{
return row[x] & col[y] & cell[x / 3][y / 3];
}

bool dfs(int cnt)
{
if (!cnt) return true;

int minv = 10;
int x, y;
for (int i = 0; i < N; i ++ )
for (int j = 0; j < N; j ++ )
if (str[i * N + j] == '.')
{
int state = get(i, j);
if (ones[state] < minv)
{
minv = ones[state];
x = i, y = j;
}
}

int state = get(x, y);
for (int i = state; i; i -= lowbit(i))
{
int t = map[lowbit(i)];
draw(x, y, t, true);
if (dfs(cnt - 1)) return true;
draw(x, y, t, false);
}

return false;
}

int main()
{
for (int i = 0; i < N; i ++ ) map[1 << i] = i;
for (int i = 0; i < 1 << N; i ++ )
for (int j = 0; j < N; j ++ )
ones[i] += i >> j & 1;

while (cin >> str, str[0] != 'e')
{
init();

int cnt = 0;
for (int i = 0, k = 0; i < N; i ++ )
for (int j = 0; j < N; j ++, k ++ )
if (str[k] != '.')
{
int t = str[k] - '1';
draw(i, j, t, true);
}
else cnt ++ ;

dfs(cnt);

puts(str);
}

return 0;
}



#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ios>
#include <locale>
#include <clocale>
#include <cassert>
#include <cstdarg>
#include <cstddef>
#include <ctime>
#include <cctype>
#include <limits>
#include <climits>
#include <cfloat>
#include <cerrno>
#include <cmath>
#include <cstalign>
#include <istream>
#include <ostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stack>
#include <list>
#include <initalizer_list>
#include <queue>
#include <memory.h>
#include <malloc.h>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <bitset>
#include <atomic>
#include <valarray>
#include <cwchar>
#include <chrono>
#include <cfenv>
#include <algorithm>
#include <regex>
#include <tuple>
#include <utility>

#include <bits/c++io.h>
#include <bits/stdc++.h>
#include <bits/move.h>
#include <bits/stdtr1c++.h>
#include <hash_map>
#include <backward/hash_map.h>
#include <hash_set>
#include <backward/hash_set.h>


# define int long long

using namespace std;

int ksc(int x, int y,int z)
{
if(! y) return 0;
int ans = ksc(x, y >> 1, z);
ans = (ans + ans) % z;
if(y & 1) ans = (ans + x) % z;
return ans;
}

int ksm(int x, int y, int z)
{
if(! y) return 1;
int ans = ksm(x, y >> 1, z);
ans = ksc(ans, ans, z);
if(y & 1) ans = ksc(ans, x, z);
return ans;
}

int solve(int a, int b, int p)
{
int s = (int) (sqrt(p) + 0.01); // 代表每一行有几个数
set [HTML_REMOVED] se;
int ans = 1; // s^0
for(int i = 0; i < s; i)
{
se.insert(ans);
ans = 1LL * ans * a % p;
}
ans = ksm(ans, p-2, p);
int c = b;
for(int i = 0; i < p - 1; i += s)
{
if(se.count(c) != 0)
{
int v = ksm(a, i, p);
while(v != b)
{
v = 1LL * v * a % p;
i
;
}
return i;
}
c = 1LL * c * ans % p;
}
return -1;
}

main()
{
int p, b, n;
cin >> p >> b >> n;
int an = solve(b, n, p);
if(~ an) cout << solve(b, n, p) << endl;
else cout << “No Solution” << endl;
return 0;
}

# include [HTML_REMOVED]

using namespace std;

int main()
{
int n;
cin >> n;
int m = n - 1;
for (int i = 1; i <= m; i ++)
{
if (i & 1) printf (“I hate that “);
else printf (“I love that “);
}
if (n & 1) printf (“I hate it “);
else printf (“I love it “);
return 0;
}