이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k;
vector<int> a[500007];
map<pair<int,int>,int> mp;
int d[500007];
namespace sub1 {
bool check() {
return 1;
}
bool f[500007];
vector<pair<int,int>> res;
int dfs(int i) {
f[i] = 1;
bool ok = (d[i]>=k);
for (const int &j : a[i]) {
if (f[j]) continue;
if (dfs(j)) {
res.push_back(pair<int,int>(min(i,j),max(i,j)));
ok = 1;
}
}
return ok;
}
void solve() {
for (int i=1; i<=n; i++) {
if (f[i]) continue;
if (d[i] < k) continue;
dfs(i);
}
for (pair<int,int> &i : res) {
i.first = mp[i];
}
sort(res.begin(),res.end());
cout << res.size() << '\n';
for (const pair<int,int> &i : res) cout << i.first << ' ';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i=1; i<n; i++) {
int u,v;
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
mp[pair<int,int>(min(u,v),max(u,v))] = i;
}
for (int i=1; i<=n; i++) {
sort(a[i].begin(),a[i].end());
}
for (int i=1; i<=m; i++) {
int x;
cin >> x;
while (x--) {
int t;
cin >> t;
d[t]++;
}
}
if (sub1::check()) {
sub1::solve();
return 0;
}
return 0;
}
# | 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... |