Submission #227136

# Submission time Handle Problem Language Result Execution time Memory
227136 2020-04-26T08:47:39 Z Bruteforceman Senior Postmen (BOI14_postmen) C++11
0 / 100
5 ms 2304 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
struct edge {
  int l, r;
  int nxtL, nxtR;
} e[maxn];
int idx[maxn];
int del[maxn];
pair <int, int> st[maxn];
bool vis[maxn];
int id;

void dfs(int x) {
  while(idx[x] != -1) {
    int i = idx[x]; 
    int y = e[i].l ^ e[i].r ^ x;
    idx[x] = (e[i].l == x) ? e[i].nxtL : e[i].nxtR;
    if(del[i]) continue; del[i] = true;
    dfs(y);
    st[id++] = make_pair(x, i);
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  memset(idx, -1, sizeof idx);
  for(int i = 0; i < m; i++) {
    scanf("%d %d", &e[i].l, &e[i].r);
    e[i].nxtL = idx[e[i].l];
    e[i].nxtR = idx[e[i].r];
    idx[e[i].l] = idx[e[i].r] = i;
  }
  dfs(1);
  reverse(st, st + id); 
  st[id++] = make_pair(1, -1);
  stack <pair <int, int>> s;
  for(int i = 0; i < id; i++) {
    int x = st[i].first;
    // cout << x << ' ' << st[i].second << endl; 
    if(vis[x]) {
       do {
         printf("%d ", 1 + s.top().second);
         vis[s.top().first] = false;
         s.pop();
       } while(s.top().first != x);
       printf("\n");
    }
    vis[x] = true;
    s.push(st[i]);
  }
 /* for(int i = id - 1; i >= 0; i--) {
    cout << st[i].first << '-' << st[i].second << endl;
  }*/
  return 0;
}

Compilation message

postmen.cpp: In function 'void dfs(int)':
postmen.cpp:19:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(del[i]) continue; del[i] = true;
     ^~
postmen.cpp:19:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(del[i]) continue; del[i] = true;
                          ^~~
postmen.cpp: In function 'int main()':
postmen.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &e[i].l, &e[i].r);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2304 KB Edge does not exist or used 2, 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2304 KB Edge does not exist or used 2, 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2304 KB Edge does not exist or used 2, 1
2 Halted 0 ms 0 KB -