比赛 |
2024暑假C班集训E |
评测结果 |
ATTTTTTTTTTTTTTTTTTTTTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA
|
题目名称 |
部落冲突 |
最终得分 |
2 |
用户昵称 |
LikableP |
运行时间 |
72.660 s |
代码语言 |
C++ |
内存使用 |
31.84 MiB |
提交时间 |
2024-07-14 11:50:33 |
显示代码纯文本
#include <iostream>
#include <fstream>
#include <cstring>
#define fo(i, l, r) for(int i = (l); i <= (r); i++)
using namespace std;
bool G[6010][6010];
bool floyed[6010][6010];
bool road[300010];
int warCount;
int war[300010];
int n, m;
int p[6010], q[6010];
bool special = true;
void Floyed() {
fo(i, 1, n) fo(j, 1, n) floyed[i][j] = G[i][j];
fo(k, 1, n) fo(i, 1, n) fo(j, 1, n) floyed[i][j] = floyed[i][j] || (floyed[i][k] && floyed[k][j]);
}
int main() {
freopen("lct.in", "r", stdin);
freopen("lct.out", "w", stdout);
cin >> n >> m;
fo(i, 1, n - 1) {
int x, y;
cin >> x >> y;
if(y != x + 1) special = false;
G[x][y] = G[y][x] = true;
}
if(special){
memset(road, true, sizeof(road));
fo(i, 1, m){
char ch;
cin >> ch;
if (ch == 'Q') {
int p, q;
cin >> p >> q;
if(p > q) swap(p, q);
bool flag = true;
fo(i, p, q - 1){
if(!road[i]) flag = false;
}
cout << (flag ? "Yes" : "No") << endl;
} else if (ch == 'C') {
int p, q;
cin >> p >> q;
if(p > q) swap(p, q);
warCount++;
war[warCount] = p;
road[war[warCount]] = false;
} else {
int x;
cin >> x;
road[war[x]] = true;
}
}
return 0;
}
fo(i, 1, m) {
char ch;
cin >> ch;
if (ch == 'Q') {
int p, q;
cin >> p >> q;
Floyed();
cout << (floyed[p][q] ? "Yes" : "No") << endl;
} else if (ch == 'C') {
int p, q;
cin >> p >> q;
G[p][q] = G[q][p] = false;
warCount++;
::p[warCount] = p;
::q[warCount] = q;
} else {
int x;
cin >> x;
int p = ::p[x], q = ::q[x];
G[p][q] = G[q][p] = true;
}
}
return 0;
}