답안 #960080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960080 2024-04-09T15:45:53 Z Flan312 Railway (BOI17_railway) C++17
100 / 100
88 ms 24444 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
using namespace std;
const int nmax = 1e5 + 2;
int n, m, k;
vector <pii> adj[nmax];
int in[nmax], out[nmax], up[nmax][17], indfs = 0;
int pos[nmax];
void dfs(int u)
{
    in[u] = ++indfs;
    for (auto &[v, i] : adj[u])
    {
        if (v == up[u][0]) continue;
        up[v][0] = u;
        pos[v] = i;
        for (int j = 1; (1 << j) <= n; ++j)
            up[v][j] = up[up[v][j - 1]][j - 1];
        dfs(v);
    }
    out[u] = indfs;
}
bool is_ancestor(int u, int v)
{
    return in[u] <= in[v] && in[v] <= out[u];
}
int lca(int u, int v)
{
    if (is_ancestor(u, v)) return u;
    if (is_ancestor(v, u)) return v;
    for (int i = 16; i >= 0; --i)
    {
        int pu = up[u][i];
        if (pu > 0 && !is_ancestor(pu, v)) u = pu;
    }
    return up[u][0];
}
int dp[nmax];
bool can[nmax];
int dfs2(int u)
{
    for (auto &[v, i] : adj[u])
    {
        if (v == up[u][0]) continue;
        dp[u] += dfs2(v);
    }
    if (dp[u] >= 2*k) can[pos[u]] = 1;
    return dp[u];
}
int main()
{
    if (ifstream(task".inp")) nx
    fast
    cin >> n >> m >> k;
    for (int u, v, i = 1; i < n; ++i)
    {
        cin >> u >> v;
        adj[u].eb(v, i);
        adj[v].eb(u, i);
    }
    dfs(1);
    for (int i = 1; i <= m; ++i)
    {
        int s;
        cin >> s;
        vector <int> ver(s);
        for (auto &j : ver) cin >> j;
        sort(ver.begin(), ver.end(), [&](int i, int j)
        {
            return in[i] < in[j];
        });
        for (int i = 0; i < ver.size(); ++i)
        {
            ++dp[ver[i]];
            ++dp[ver[(i + 1) % s]];
            dp[lca(ver[i], ver[(i + 1) % s])] -= 2;
        }
    }
    dfs2(1);
    int ans = 0;
    for (int i = 1; i < n; ++i)
        if (can[i]) ++ans;
    cout << ans << '\n';
    for (int i = 1; i < n; ++i)
        if (can[i]) cout << i << ' ';
}

Compilation message

railway.cpp: In function 'int main()':
railway.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int i = 0; i < ver.size(); ++i)
      |                         ~~^~~~~~~~~~~~
railway.cpp:7:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
railway.cpp:61:31: note: in expansion of macro 'nx'
   61 |     if (ifstream(task".inp")) nx
      |                               ^~
railway.cpp:7:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |                                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:61:31: note: in expansion of macro 'nx'
   61 |     if (ifstream(task".inp")) nx
      |                               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 5 ms 5996 KB Output is correct
3 Correct 5 ms 5984 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 5 ms 6272 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 5 ms 5980 KB Output is correct
9 Correct 6 ms 5980 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 1 ms 4792 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 5 ms 5996 KB Output is correct
3 Correct 5 ms 5984 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 5 ms 6272 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 5 ms 5980 KB Output is correct
9 Correct 6 ms 5980 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 1 ms 4792 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 13 ms 6236 KB Output is correct
16 Correct 13 ms 6236 KB Output is correct
17 Correct 15 ms 6384 KB Output is correct
18 Correct 5 ms 6232 KB Output is correct
19 Correct 4 ms 5976 KB Output is correct
20 Correct 12 ms 6468 KB Output is correct
21 Correct 14 ms 6492 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 4 ms 5976 KB Output is correct
24 Correct 5 ms 5980 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 4 ms 6364 KB Output is correct
28 Correct 4 ms 6072 KB Output is correct
29 Correct 4 ms 5980 KB Output is correct
30 Correct 4 ms 5980 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 24148 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 60 ms 24000 KB Output is correct
4 Correct 47 ms 23820 KB Output is correct
5 Correct 53 ms 24404 KB Output is correct
6 Correct 51 ms 24400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 20328 KB Output is correct
2 Correct 61 ms 16768 KB Output is correct
3 Correct 57 ms 16468 KB Output is correct
4 Correct 79 ms 16752 KB Output is correct
5 Correct 54 ms 16464 KB Output is correct
6 Correct 56 ms 20304 KB Output is correct
7 Correct 54 ms 20300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 20328 KB Output is correct
2 Correct 61 ms 16768 KB Output is correct
3 Correct 57 ms 16468 KB Output is correct
4 Correct 79 ms 16752 KB Output is correct
5 Correct 54 ms 16464 KB Output is correct
6 Correct 56 ms 20304 KB Output is correct
7 Correct 54 ms 20300 KB Output is correct
8 Correct 59 ms 20176 KB Output is correct
9 Correct 65 ms 20312 KB Output is correct
10 Correct 47 ms 24248 KB Output is correct
11 Correct 47 ms 24224 KB Output is correct
12 Correct 41 ms 16316 KB Output is correct
13 Correct 44 ms 16264 KB Output is correct
14 Correct 69 ms 16524 KB Output is correct
15 Correct 51 ms 16468 KB Output is correct
16 Correct 54 ms 16412 KB Output is correct
17 Correct 56 ms 16464 KB Output is correct
18 Correct 59 ms 16468 KB Output is correct
19 Correct 64 ms 16856 KB Output is correct
20 Correct 72 ms 20304 KB Output is correct
21 Correct 57 ms 20564 KB Output is correct
22 Correct 53 ms 20308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 5 ms 5996 KB Output is correct
3 Correct 5 ms 5984 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 5 ms 6272 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 5 ms 5980 KB Output is correct
9 Correct 6 ms 5980 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 1 ms 4792 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 13 ms 6236 KB Output is correct
16 Correct 13 ms 6236 KB Output is correct
17 Correct 15 ms 6384 KB Output is correct
18 Correct 5 ms 6232 KB Output is correct
19 Correct 4 ms 5976 KB Output is correct
20 Correct 12 ms 6468 KB Output is correct
21 Correct 14 ms 6492 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 4 ms 5976 KB Output is correct
24 Correct 5 ms 5980 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 4 ms 6364 KB Output is correct
28 Correct 4 ms 6072 KB Output is correct
29 Correct 4 ms 5980 KB Output is correct
30 Correct 4 ms 5980 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 53 ms 24148 KB Output is correct
37 Correct 1 ms 4696 KB Output is correct
38 Correct 60 ms 24000 KB Output is correct
39 Correct 47 ms 23820 KB Output is correct
40 Correct 53 ms 24404 KB Output is correct
41 Correct 51 ms 24400 KB Output is correct
42 Correct 54 ms 20328 KB Output is correct
43 Correct 61 ms 16768 KB Output is correct
44 Correct 57 ms 16468 KB Output is correct
45 Correct 79 ms 16752 KB Output is correct
46 Correct 54 ms 16464 KB Output is correct
47 Correct 56 ms 20304 KB Output is correct
48 Correct 54 ms 20300 KB Output is correct
49 Correct 59 ms 20176 KB Output is correct
50 Correct 65 ms 20312 KB Output is correct
51 Correct 47 ms 24248 KB Output is correct
52 Correct 47 ms 24224 KB Output is correct
53 Correct 41 ms 16316 KB Output is correct
54 Correct 44 ms 16264 KB Output is correct
55 Correct 69 ms 16524 KB Output is correct
56 Correct 51 ms 16468 KB Output is correct
57 Correct 54 ms 16412 KB Output is correct
58 Correct 56 ms 16464 KB Output is correct
59 Correct 59 ms 16468 KB Output is correct
60 Correct 64 ms 16856 KB Output is correct
61 Correct 72 ms 20304 KB Output is correct
62 Correct 57 ms 20564 KB Output is correct
63 Correct 53 ms 20308 KB Output is correct
64 Correct 57 ms 20308 KB Output is correct
65 Correct 67 ms 16468 KB Output is correct
66 Correct 88 ms 16396 KB Output is correct
67 Correct 87 ms 16384 KB Output is correct
68 Correct 46 ms 16196 KB Output is correct
69 Correct 60 ms 16160 KB Output is correct
70 Correct 84 ms 20564 KB Output is correct
71 Correct 56 ms 20308 KB Output is correct
72 Correct 1 ms 4700 KB Output is correct
73 Correct 4 ms 6004 KB Output is correct
74 Correct 6 ms 5976 KB Output is correct
75 Correct 1 ms 4700 KB Output is correct
76 Correct 1 ms 4700 KB Output is correct
77 Correct 5 ms 6236 KB Output is correct
78 Correct 5 ms 5980 KB Output is correct
79 Correct 4 ms 5980 KB Output is correct
80 Correct 4 ms 5828 KB Output is correct
81 Correct 1 ms 4700 KB Output is correct
82 Correct 1 ms 4700 KB Output is correct
83 Correct 1 ms 4792 KB Output is correct
84 Correct 1 ms 4700 KB Output is correct
85 Correct 1 ms 4700 KB Output is correct
86 Correct 13 ms 6236 KB Output is correct
87 Correct 13 ms 6232 KB Output is correct
88 Correct 14 ms 6236 KB Output is correct
89 Correct 6 ms 6376 KB Output is correct
90 Correct 5 ms 5948 KB Output is correct
91 Correct 14 ms 6492 KB Output is correct
92 Correct 14 ms 6492 KB Output is correct
93 Correct 1 ms 4696 KB Output is correct
94 Correct 48 ms 24176 KB Output is correct
95 Correct 52 ms 24000 KB Output is correct
96 Correct 46 ms 23684 KB Output is correct
97 Correct 53 ms 24148 KB Output is correct
98 Correct 54 ms 24444 KB Output is correct
99 Correct 69 ms 16540 KB Output is correct
100 Correct 63 ms 16540 KB Output is correct
101 Correct 77 ms 16408 KB Output is correct
102 Correct 74 ms 16796 KB Output is correct
103 Correct 59 ms 20384 KB Output is correct
104 Correct 62 ms 20568 KB Output is correct
105 Correct 59 ms 20320 KB Output is correct
106 Correct 69 ms 20308 KB Output is correct
107 Correct 71 ms 20220 KB Output is correct
108 Correct 50 ms 24148 KB Output is correct
109 Correct 46 ms 24140 KB Output is correct
110 Correct 40 ms 16216 KB Output is correct
111 Correct 55 ms 16212 KB Output is correct
112 Correct 65 ms 16404 KB Output is correct
113 Correct 57 ms 16464 KB Output is correct