Submission #48060

# Submission time Handle Problem Language Result Execution time Memory
48060 2018-05-09T17:41:44 Z Extazy Pipes (CEOI15_pipes) C++17
100 / 100
1443 ms 12164 KB
#include <bits/stdc++.h>
#define endl '\n'
#define time akghahgahgkahjgaj

using namespace std;

const int N = 100007;

struct dsu {
  int n,parents[N];

  void initialize(int k) {
    n=k;
    for(int i=1;i<=n;i++) {
      parents[i]=i;
    }
  }

  int find(int x) {
    while(x!=parents[x]) {
      parents[x]=parents[parents[x]];
      x=parents[x];
    }
    return x;
  }
} uf1, uf2;

int n,m;
int time[N],low[N],current_time;
vector < int > v[N];

void dfs(int node, int from=-1) {
  low[node]=time[node]=++current_time;

  int i;

  for(i=0;i<(int)(v[node].size());i++) if(v[node][i]!=from) {
    if(time[v[node][i]]==0) {
      dfs(v[node][i],node);
      if(low[v[node][i]]>time[node]) if(uf2.find(node)!=uf2.find(v[node][i])) {
        printf("%d %d\n", node, v[node][i]);
      }
      low[node]=min(low[node],low[v[node][i]]);
    }
    else {
      low[node]=min(low[node],time[v[node][i]]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i,x,y,fx,fy;

  scanf("%d %d", &n, &m);

  uf1.initialize(n);
  uf2.initialize(n);

  for(i=1;i<=m;i++) {
    scanf("%d %d", &x, &y);

    fx=uf1.find(x);
    fy=uf1.find(y);

    if(fx!=fy) {
      uf1.parents[fx]=fy;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    else {
      fx=uf2.find(x);
      fy=uf2.find(y);

      if(fx!=fy) {
        uf2.parents[fx]=fy;
        v[x].push_back(y);
        v[y].push_back(x);
      }
    }
  }

  for(i=1;i<=n;i++) if(time[i]==0) {
    dfs(i);
  }

  return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2776 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3116 KB Output is correct
2 Correct 7 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 3052 KB Output is correct
2 Correct 112 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 3588 KB Output is correct
2 Correct 231 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 4920 KB Output is correct
2 Correct 280 ms 4672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 9428 KB Output is correct
2 Correct 407 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 738 ms 10332 KB Output is correct
2 Correct 695 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 969 ms 12164 KB Output is correct
2 Correct 904 ms 8852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 12132 KB Output is correct
2 Correct 1130 ms 8824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1443 ms 11624 KB Output is correct
2 Correct 1354 ms 9776 KB Output is correct