Submission #669552

# Submission time Handle Problem Language Result Execution time Memory
669552 2022-12-06T17:37:46 Z BlackC Pipes (CEOI15_pipes) C++17
Compilation error
0 ms 0 KB
//
//  main.cpp
//  C
//
//  Created by Sajad Zare on 4/23/22.
//


#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <utility>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <iomanip>
using namespace std;
const int maxn=1e5+2;
int parent[maxn];
int parent2[maxn];
int sz[maxn];
int sz2[maxn];
int seen[maxn];
int st[maxn];
int parent3[maxn];
int lowest[maxn];
int tm=0;
vector<int> N[maxn];
vector<pair<int, int>>t1;
vector<pair<int, int>>t2;
int x,y;
int get_root(int v){
    if (parent[v]!=v){
        parent[v]=get_root(parent[v]);
    }
    return parent[v];
}
int get_root2(int v){
    if (parent2[v]!=v){
        parent2[v]=get_root(parent2[v]);
    }
    return parent2[v];
}
bool Union(int u,int v){
    u=get_root(u);
    v=get_root(v);
    if (u==v){
        return 1;
    }
    if (sz[v]<sz[u]){
        parent[v]=u;
        sz[u]+=sz[v];
    }
    else{
        parent[u]=v;
        sz[v]+=sz[u];
    }
    return 0;
}
bool Union2(int u,int v){
    x=u;
    y=v;
    u=get_root2(u);
    v=get_root2(v);
    if (u==v){
        return 0;
    }
    t2.push_back({x,y});
    if (sz2[v]<sz2[u]){
        parent2[v]=u;
        sz2[u]+=sz2[v];
    }
    else{
        parent2[u]=v;
        sz2[v]+=sz2[u];
    }
    return 1;
}
void dfs(int node){
    seen[node]=1;
    tm+=1;
    st[node]=tm;
    lowest[node]=tm;
    //stft.push_back(node);
    for (int n: N[node]){
        if (seen[n]!=1){
            parent3[n]=node;
            dfs(n);
            lowest[node]=min(lowest[node], lowest[n]);
            if (lowest[n]>st[node]){
                cout << node << ' ' << n << "\n";
            }
        }
        else if (n!=parent3[node]){
            lowest[node]=min(lowest[node],st[n]);
        }
    }
    //ft[node]=t;
    //stft.push_back(node);
}
//const int M = 1000000007;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    for (int i=1;i<n+1;i++){
        parent[i]=i;
        sz[i]=1;
    }
    for (int i=1;i<n+1;i++){
        parent2[i]=i;
        sz2[i]=1;
    }
    int u,v;
    for (int i=0;i<m;i++){
        cin >> u >> v;
        if (Union(u, v)){
            Union2(u, v);
        }
        else{
            t1.push_back({u,v});
        }
    }
    int f,ff;
    //int startnode=t1[0].first;
    for (int i=0;i<t1.size();i++){
        f=t1[i].first;
        ff=t1[i].second;
        N[f].push_back(ff);
        N[ff].push_back(f);
    }
    for (int i=0;i<t2.size();i++){
        f=t2[i].first;
        ff=t2[i].second;
        N[f].push_back(ff);
        N[ff].push_back(f);
    }
    //cout << startnode << endl;
    for (int i=1;i<n+1;i++){
        if (seen[i]!=1){
            dfs(i);
        }
    }
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:90:5: error: reference to 'tm' is ambiguous
   90 |     tm+=1;
      |     ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr.h:148,
                 from /usr/include/c++/10/ext/atomicity.h:35,
                 from /usr/include/c++/10/bits/ios_base.h:39,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from pipes.cpp:9:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
pipes.cpp:36:5: note:                 'int tm'
   36 | int tm=0;
      |     ^~
pipes.cpp:91:14: error: reference to 'tm' is ambiguous
   91 |     st[node]=tm;
      |              ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr.h:148,
                 from /usr/include/c++/10/ext/atomicity.h:35,
                 from /usr/include/c++/10/bits/ios_base.h:39,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from pipes.cpp:9:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
pipes.cpp:36:5: note:                 'int tm'
   36 | int tm=0;
      |     ^~
pipes.cpp:92:18: error: reference to 'tm' is ambiguous
   92 |     lowest[node]=tm;
      |                  ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr.h:148,
                 from /usr/include/c++/10/ext/atomicity.h:35,
                 from /usr/include/c++/10/bits/ios_base.h:39,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from pipes.cpp:9:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
pipes.cpp:36:5: note:                 'int tm'
   36 | int tm=0;
      |     ^~
pipes.cpp: In function 'int main()':
pipes.cpp:136:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for (int i=0;i<t1.size();i++){
      |                  ~^~~~~~~~~~
pipes.cpp:142:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     for (int i=0;i<t2.size();i++){
      |                  ~^~~~~~~~~~