이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define
#define int long long
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define file "file"
#define bit(x, y) ((y >> x) & 1)
#define __lcm(a, b) a * b / __gcd(a, b)
#define R(x) {cout << x << "\n"; return;}
#define coutf(x) cout << fixed << setprecision(x)
#define inter(a) cout << a << "\n"; fflush(stdout)
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// declare
const int N = 1e5;
int n, m, k, idx, in[N + 5], pre[N + 5], kk[N + 5];
vector <int> g[N + 5];
map <pair<int,int>,int> mp;
struct Lca_O1{
vector <int> order;
int h[N + 5], pos[N + 5], ST[20][2 * N + 5];
void dfs(int i, int p)
{
in[i] = ++idx;
order.push_back(i);
pos[i] = order.size();
for (int j : g[i])
if (j != p)
{
h[j] = h[i] + 1;
dfs(j, i);
order.push_back(i);
}
}
int P(int a, int b)
{
return h[a] < h[b] ? a : b;
}
void Build()
{
int sz = order.size();
for (int i = 1; i <= sz; ++i) ST[0][i] = order[i - 1];
for (int i = 1; i < 20; ++i)
if ((1 << i) <= sz)
{
for (int j = 1; j <= sz - (1 << i) + 1; ++j)
ST[i][j] = P(ST[i - 1][j], ST[i - 1][j + (1 << (i - 1))]);
}
}
int lca(int l, int r)
{
l = pos[l], r = pos[r];
if (l > r) swap(l, r);
int bit = __lg(r - l + 1);
return P(ST[bit][l], ST[bit][r - (1 << bit) + 1]);
}
// declare h[1]
} lc;
void dfs(int i, int p)
{
for (int j : g[i])
if (j != p)
{
dfs(j, i);
kk[j] = mp[{i, j}];
pre[i] += pre[j];
}
}
void Update(int u, int v)
{
int p = lc.lca(u, v);
++pre[u];
++pre[v];
pre[p] -= 2;
}
void Solve()
{
cin >> n >> m >> k;
for (int i = 1; i < n; ++i)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
mp[{u, v}] = mp[{v, u}] = i;
}
lc.dfs(1, 0);
lc.Build();
for (int i = 1; i <= m; ++i)
{
int d;
cin >> d;
vector <int> v;
while (d--)
{
int x;
cin >> x;
v.push_back(x);
}
sort(all(v),[&](int a, int b)
{
return in[a] < in[b];
});
v.push_back(v[0]);
for (int i = 1; i < v.size(); ++i)
Update(v[i], v[i - 1]);
}
dfs(1, 0);
vector <int> ans;
for (int i = 2; i <= n; ++i)
if (pre[i] / 2 >= k) ans.push_back(kk[i]);
cout << ans.size() << "\n";
sort(all(ans));
for (int x : ans) cout << x << ' ';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen(file ".inp", "r"))
{
freopen (file ".inp", "r", stdin);
freopen (file ".out", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--)
Solve();
cerr << "\nTIME: " << 1000 * clock() / CLOCKS_PER_SEC << "ms.";
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp: In function 'void Solve()':
railway.cpp:116:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (int i = 1; i < v.size(); ++i)
| ~~^~~~~~~~~~
railway.cpp: In function 'int main()':
railway.cpp:134:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | freopen (file ".inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:135:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | freopen (file ".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |