답안 #1116154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116154 2024-11-21T09:38:28 Z vjudge1 Pipes (CEOI15_pipes) C++17
70 / 100
2117 ms 46916 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

const int lim=1e5+1;

int parent[lim];
int find(int i){
  if(i==parent[i])return i;
  return parent[i]=find(parent[i]);
}
void unite(int i,int j){
  i=find(i),j=find(j);
  parent[i]=j;
}

struct vec{
  int*targ=new int[2],size=2,have=0;
  void pb(int t){
    if(have==size){
      int*newy=new int[int(size*1.5)];
      for(int i=0;i<size;i++)newy[i]=targ[i];
      size*=1.5;
      delete targ;
      targ=newy;
    }
    targ[have++]=t;
  }
  void clear(){
    have=0;
    size=2;
    delete targ;
    targ=new int[2];
  }
};

vec v[lim];
vector<pair<int,int>>edges;

int tin[lim],tout[lim],tt=1;

int dfs(int node,int par){
  if(tin[node])return tin[node];
  tout[node]=tin[node]=tt++;
  for(int i=0;i<v[node].have;i++){
    int j=v[node].targ[i];
    if(j==par)continue;
    if(tin[j]){
      tout[node]=min(tout[node],tin[j]);
      unite(node,j);
    }else{
      int res=dfs(j,node);
      if(res<=tin[node]){
        unite(node,j);
      }
      tout[node]=min(tout[node],res);
    }
  }
  return tout[node];
}

int n,m;
void findans(){
  for(int i=0;i<=n;i++)v[i].clear();
  for(auto[x,y]:edges){
    v[find(x)].pb(find(y));
    v[find(y)].pb(find(x));
  }
  for(int i=0;i<=n;i++){
    tout[i]=tin[i]=0;
  }
  tt=1;
  for(int i=1;i<=n;i++){
    if(!tin[i])dfs(i,0);
  }
  for(int i=0;i<edges.size();i++){
    if(find(edges[i].first)==find(edges[i].second)){
      swap(edges[i],edges.back());
      edges.pop_back();
      i--;
    }
  }
}

int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++)parent[i]=i;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    if(find(x)!=find(y))edges.pb({x,y});
    if(edges.size()==150000)findans();
  }
  findans();
  for(auto[x,y]:edges)cout<<x<<' '<<y<<'\n';
}

Compilation message

pipes.cpp: In function 'void findans()':
pipes.cpp:76:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i=0;i<edges.size();i++){
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 6 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6224 KB Output is correct
2 Correct 8 ms 5968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 9556 KB Output is correct
2 Correct 209 ms 9408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 9968 KB Output is correct
2 Correct 347 ms 9376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 500 ms 10688 KB Output is correct
2 Correct 447 ms 10444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 705 ms 13856 KB Output is correct
2 Correct 640 ms 10888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1033 ms 14016 KB Output is correct
2 Correct 1078 ms 11932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1303 ms 13320 KB Output is correct
2 Runtime error 1340 ms 31128 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1708 ms 13316 KB Output is correct
2 Runtime error 1820 ms 36868 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2117 ms 13248 KB Output is correct
2 Runtime error 2008 ms 46916 KB Memory limit exceeded
3 Halted 0 ms 0 KB -