haley001 @ 2024-08-24 15:48:56
#include<bits/stdc++.h>
#define int long long
#define endl <<'\n';
#define kk <<' '<<
#define kkm <<' ' endl
#define out cout<<
#define F(x,a,b,c) for(int x = (a); x <= (b); x+=(c))
#define FF(x,a,b,c) for(int x = (a); x >= (b); x-=(c))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define pbk push_back
#define continue creak
#define sit short
#define ud using namespace std;
#define qwq return
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define main signed main()
#define W while
ud
static char buf[200001], * pa(buf), * pb(buf);
#define gc pa == pb && (pb = (pa = buf) + fread(buf, 1, 100000, stdin), pa == pb) ? EOF : *pa++
void read(int &x) {
x = 0;
int f = 1;
char ch = gc;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = gc;
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - 48, ch = gc;
x *= f;
}
template <typename T, typename ...Args> void read(T &nums, Args &...args) {
read(nums);
read(args...);
}
int f[200010], n, m, s[200010], kuai;
string sta[200010];
bool os[200010];
vector<int>e[200010];
int getfa(int x) {
return f[x] == x ? x : f[x] = getfa(f[x]);
}
void merge(int x, int y) {
x = getfa(x), y = getfa(y);
f[x] = y;
}
main{
ios
read(n, m);
F(i, 1, n, 1) f[i] = i;
F(i, 1, m, 1) {
int x, y;
read(x, y);
e[x].push_back(y);
e[y].push_back(x);
}
FF(i, n, 1, 1) read(s[i]);
F(i, 1, n, 1) {
kuai++;
os[s[i]] = 1;
F(j, 0, e[s[i]].size() - 1, 1) if (os[e[s[i]][j]] && getfa(s[i]) != getfa(e[s[i]][j]))merge(s[i], e[s[i]][j]), kuai--;
if (kuai == 1)sta[i] = "YES";
else sta[i] = "NO";
}
FF(i, n, 1, 1) out sta[i] endl
qwq 0;
}
by haley001 @ 2024-08-24 15:52:11
P1197 RE 60pts
#include<bits/stdc++.h>
#define int long long
#define endl <<'\n';
#define kk <<' '<<
#define kkm <<' ' endl
#define out cout<<
#define F(x,a,b,c) for(int x = (a); x <= (b); x+=(c))
#define FF(x,a,b,c) for(int x = (a); x >= (b); x-=(c))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define pbk push_back
#define creak continue;
#define sit short
#define ud using namespace std;
#define qwq return
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define main signed main()
#define W while
ud
static char buf[200001], * pa(buf), * pb(buf);
#define gc pa == pb && (pb = (pa = buf) + fread(buf, 1, 100000, stdin), pa == pb) ? EOF : *pa++
void read(int &x) {
x = 0;
int f = 1;
char ch = gc;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = gc;
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - 48, ch = gc;
x *= f;
}
template <typename T, typename ...Args> void read(T &nums, Args &...args) {
read(nums);
read(args...);
}
int f[400010], n, m, s[400010], kuai, k;
stack<int>sta;
bool os[400010];
vector<int>e[400010];
int getfa(int x) {
return f[x] == x ? x : f[x] = getfa(f[x]);
}
void merge(int x, int y) {
x = getfa(x), y = getfa(y);
f[x] = y;
}
main{
ios
read(n, m);
F(i, 0, n, 1) f[i] = i;
F(i, 1, m, 1) {
int x, y;
read(x, y);
e[x].push_back(y);
e[y].push_back(x);
}
read(k);
kuai = n - k;
FF(i, k, 1, 1) read(s[i]), os[s[i]] = 1;
F(i, 0, n - 1, 1) {
if (os[i]) creak;
F(j, 0, e[i].size() - 1, 1) if (!os[e[i][j]] && getfa(i) != getfa(e[i][j]))merge(i, e[i][j]), kuai--;
}
F(i, 1, k, 1) {
sta.push(kuai);
kuai++;
os[s[i]] = 0;
F(j, 0, e[s[i]].size() - 1, 1) if (!os[e[s[i]][j]] && getfa(s[i]) != getfa(e[s[i]][j]))merge(s[i], e[s[i]][j]), kuai--;
}
sta.push(kuai);
while (sta.size()) {
out sta.top() endl
sta.pop();
}
qwq 0;
}