Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- using namespace std;
- const int MAXN=12000;
- vector<pair<int,int> > g[MAXN];
- bool f[MAXN];
- bool met[MAXN];
- int n,m,k;
- bool dfs(int v) {
- if (met[v]) return f[v];
- met[v]=true;
- int kol=0;
- for (size_t i=0;i<g[v].size();i++) {
- int to=g[v][i].first;
- if (dfs(to)) kol++;
- }
- if (kol>k) f[v]=true;
- else f[v]=false;
- return f[v];
- }
- void wr(string s) {
- cout << s << endl;
- fflush(stdout);
- }
- int ans[MAXN];
- int len;
- int main()
- {
- int i,a,b,v;
- cin >> n >> m >> k;
- for (i=1;i<=m;i++) {
- cin >> a >> b;
- g[a].push_back(make_pair(b,i));
- }
- f[n]=true;
- met[n]=true;
- if (dfs(1)) {
- wr("NO");
- return 0;
- }
- v=1;
- while (v!=-1) {
- len=0;
- for (i=0;i<(int)g[v].size();i++) {
- int to=g[v][i].first,num=g[v][i].second;
- if (dfs(to)) ans[len++]=num;
- }
- cout << len;
- for (i=0;i<len;i++)
- cout << ' ' << ans[i];
- wr("");
- cin >> v;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement