Submission #695097

#TimeUsernameProblemLanguageResultExecution timeMemory
695097Farhan_HYRailway (BOI17_railway)C++14
0 / 100
1086 ms33096 KiB
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
/// Benzema is the best player in the world
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int LOG = 28;
int n, m, k;
bool nodes[N];
vector<int> adj[N], ans;
int cnt = 0;

bool dfs(int node, int par) {
    bool ret = nodes[node];
    for(auto x: adj[node]) {
        if (x == par) continue;
        ret |= dfs(x, node);
    }
    if (ret == 1) cnt++;
    return ret;
}

main() {
    IOS
    cin >> n >> m >> k;
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 1; i <= m; i++) {
        int s;
        cin >> s;
        int x;
        for(int j = 1; j <= n; j++) nodes[j] = 0;
        for(int j = 1; j <= s; ++j) {
            cin >> x;
            nodes[x] = 1;
        }
        cnt = 0;
        dfs(x, x);
        if (cnt - 1 <= k) ans.push_back(i);
    }
    cout << ans.size() << '\n';
    for(auto x: ans) cout << x << ' ';
}

Compilation message (stderr)

railway.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...