QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546962 | #2583. 战略游戏 | wangyangjena | 0 | 1027ms | 65648kb | C++14 | 3.4kb | 2024-09-04 16:16:54 | 2024-09-04 16:16:54 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
// #pragma GCC optimize(2)
using namespace std;
const int N = 2e5 + 10, MOD = 998244353;
int t;
int n, m, q;
int u, v, k, s[N];
vector <int> e[N], ee[N], g[N];
int dfn[N], low[N], cdfn, cnt;
vector <int> st;
void Tarjan(int x, int y){
dfn[x] = low[x] = ++cdfn;
st.push_back(x);
for(auto i : e[x]){
if(!dfn[i]){
Tarjan(i, x);
low[x] = min(low[x], low[i]);
if(low[i] == dfn[x]){
++cnt;
int tp = st.back();
do{
tp = st.back();
st.pop_back();
ee[cnt].push_back(tp);
ee[tp].push_back(cnt);
// cout << cnt << " " << tp << "\n";
}while(tp != i);
ee[cnt].push_back(x);
ee[x].push_back(cnt);
// cout << cnt << " " << x << "\n";
}
}else{
low[x] = min(low[x], dfn[i]);
}
}
}
int si[N], son[N], top[N], fa[N], dep[N];
void Dfs1(int x, int y){
si[x] = 1;
fa[x] = y;
dep[x] = dep[y] + 1;
for(auto i : ee[x]){
if(i == y) continue;
Dfs1(i, x);
si[x] += si[i];
if(si[i] > si[son[x]]) son[x] = i;
}
}
void Dfs2(int x, int tp){
top[x] = tp;
if(son[x]) Dfs2(son[x], tp);
for(auto i : ee[x]){
if(top[i]) continue;
Dfs2(i, i);
}
}
int Lca(int x, int y){
while(top[x] != top[y]){
if(dep[top[x]] < dep[top[y]]){
swap(x, y);
}
x = fa[top[x]];
}
if(dep[x] < dep[y]) return x;
else return y;
}
bool cmp(int x, int y){
return dfn[x] < dfn[y];
}
int dis[N];
bool tag[N];
void Get_dis(int x, int y){
dfn[x] = ++cdfn;
dis[x] = dis[y] + (1 <= x && x <= n);
for(auto i : ee[x]){
if(i == y) continue;
Get_dis(i, x);
}
}
signed main(){
// freopen("1.in", "r", stdin);
cin >> t;
while(t--){
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
cnt = n;
Tarjan(1, 0);
Dfs1(1, 0);
Dfs2(1, 1);
cdfn = 0;
Get_dis(1, 0);
cin >> q;
for(int i = 1; i <= q; i++){
cin >> k;
for(int j = 1; j <= k; j++){
cin >> s[j];
tag[s[j]] = 1;
}
sort(s + 1, s + 1 + k, cmp);
int lim = k;
for(int j = 2; j <= k; j++){
int lca = Lca(s[j - 1], s[j]);
if(lca != s[j - 1] && lca != s[j]) s[++lim] = lca;
}
sort(s + 1, s + 1 + lim, cmp);
int ans = 0;
ans += !tag[s[1]];
for(int j = 2; j <= lim; j++){
int lca = Lca(s[j - 1], s[j]);
ans += dis[s[j]] - dis[lca] - tag[s[j]];
}
cout << ans << "\n";
for(int j = 1; j <= cnt; j++) tag[s[j]] = 0;
}
for(int i = 1; i <= cnt; i++){
e[i].clear();
ee[i].clear();
dis[i] = top[i] = fa[i] = son[i] = si[i] = 0;
dfn[i] = low[i] = 0;
}
cdfn = 0;
}
}
详细
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 1027ms
memory: 65648kb
input:
10 94814 186251 42720 65317 33135 40188 90524 91057 15157 59320 56261 84256 49874 66210 18118 38018 34500 43670 14570 37867 53678 90002 13331 40076 27677 48562 36311 65435 29685 49754 22695 61837 59763 84023 2954 70002 18405 72897 7652 64325 69023 79028 27045 81899 26653 32017 1461 81255 6241 78409 ...
output:
10842 1733 17003 6950 3081 12247 9064 5817 5912 4840 6920 32177 14220 2021 54095 13636 35977 54537 47758 8286 51352 47579 86029 46711 27894 32639 51745 10230 8399 11304 45143 52011 58472 439 2726 41590 8327
result:
wrong answer 7th lines differ - expected: '9063', found: '9064'
Test #2:
score: 0
Time Limit Exceeded
input:
10 98254 198477 14613 72237 63083 73551 14567 32237 32006 56998 14940 52592 52150 61985 3972 84462 19680 42800 9518 55226 52089 66431 42873 68721 4698 93512 53178 79801 11807 42183 45906 77619 45069 47574 16109 83638 19343 49330 30148 51345 73355 83865 37818 69769 54127 92904 32072 92335 7056 71015 ...
output:
32215 45633 10703 9929 5065 5453 21134 1147 10520 8383 14579 4868 24197 19084 19548 52667 5751 8083 35026 36319 21654 4431 26616 29113 41250 5024 31323 34532 21542 18072 33180 30001 22532 43538 9529 14566 14622 20347 15862 5081 12383 16383 17132 7831 3422 7814 29927 2417 24145 8549 1450 33208 6270 1...
result:
Test #3:
score: 0
Time Limit Exceeded
input:
10 46832 199154 1937 21636 422 25158 5067 12645 42564 46740 4459 16622 3322 11404 10269 16390 28904 37319 24540 25151 21880 37822 12789 18753 7634 16767 25495 38865 36915 43797 26907 45920 31649 35332 18827 38743 16391 32795 5736 42007 3936 31488 1622 13275 2420 19285 19601 41219 4797 20725 12352 45...
output:
3339 8701 1771 7277 10508 5825 5044 14372 2864 991 606 14039 9919 8375 5429 5441 3941 3677 1350 596 4748 970 1669 9439 9298 5551 3286 118 1563 7465 204 2500 780 82 7560 959 797 1640 6131 3500 5826 914 1371 2232 3856 4591 14439 13172 2933 1900 5192 3717 1155 11892 5731 13205 344 1801 2285 506 225 170...