Submission #1098837

#TimeUsernameProblemLanguageResultExecution timeMemory
1098837AliHasanliMonthly railway pass (LMIO18_menesinis_bilietas)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<char,pair<int,int>>>edges; vector<int>g[500001],g2[500001]; int visit[500001]; void dfs(int node,int p,int col) { visit[node]=col; for(int go:g[node]) if(go!=p && visit[go]==0) dfs(go,node,col); } bool selected[500001]; int main() { int v,e,comp=0; cin>>v>>e; while(e--) { char c; int a,b; cin>>a>>b>>c; edges.push_back({c,{a,b}}); } //sort(edges.begin(),edges.end()); for(int i=edges.size()-1;i>=0;i--) { if(edges[i].first=='T') { g[edges[i].second.first].push_back(edges[i].second.second); g[edges[i].second.second].push_back(edges[i].second.first); } } for(int i=1;i<=v;i++) { if(visit[i]==0)dfs(i,0,comp+1), comp++; } //cout<<"comp: "<<comp<<endl; //for(int i=1;i<=v;i++)cout<<visit[i]<<" ";cout<<endl; int cav=0; /* for(int i=1;i<=v;i++) for(int n:g[i]) if(visit[i]!=visit[n])g2[i].push_back(n),g2[n].push_back(i); */ for(int i=0;i<edges.size();i++) if(edges[i].first=='A') g2[visit[edges[i].second.first]].push_back(visit[edges[i].second.second]),g2[visit[edges[i].second.second]].push_back(visit[edges[i].second.first]); for(int i=1;i<=v;i++) { int ini=comp-1; for(int go:g2[visit[i]]) { if(visit[i]!=go && selected[go]==0) { ini--; selected[go]=1; } } //cout<<"i: "<<i<<" ini: "<<ini<<endl; if(ini==0)cav++; for(int go:g2[visit[i]]) selected[go]=0; } cout<<cav; return 0; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'void dfs(int, int, int)':
menesinis_bilietas.cpp:8:5: error: reference to 'visit' is ambiguous
    8 |     visit[node]=col;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:10:21: error: reference to 'visit' is ambiguous
   10 |         if(go!=p && visit[go]==0)
      |                     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:36:12: error: reference to 'visit' is ambiguous
   36 |         if(visit[i]==0)dfs(i,0,comp+1),
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<char, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0;i<edges.size();i++)
      |                 ~^~~~~~~~~~~~~
menesinis_bilietas.cpp:49:16: error: reference to 'visit' is ambiguous
   49 |             g2[visit[edges[i].second.first]].push_back(visit[edges[i].second.second]),g2[visit[edges[i].second.second]].push_back(visit[edges[i].second.first]);
      |                ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:49:56: error: reference to 'visit' is ambiguous
   49 |             g2[visit[edges[i].second.first]].push_back(visit[edges[i].second.second]),g2[visit[edges[i].second.second]].push_back(visit[edges[i].second.first]);
      |                                                        ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:49:90: error: reference to 'visit' is ambiguous
   49 |             g2[visit[edges[i].second.first]].push_back(visit[edges[i].second.second]),g2[visit[edges[i].second.second]].push_back(visit[edges[i].second.first]);
      |                                                                                          ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:49:131: error: reference to 'visit' is ambiguous
   49 |             g2[visit[edges[i].second.first]].push_back(visit[edges[i].second.second]),g2[visit[edges[i].second.second]].push_back(visit[edges[i].second.first]);
      |                                                                                                                                   ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:53:23: error: reference to 'visit' is ambiguous
   53 |         for(int go:g2[visit[i]])
      |                       ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:55:16: error: reference to 'visit' is ambiguous
   55 |             if(visit[i]!=go && selected[go]==0)
      |                ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~
menesinis_bilietas.cpp:63:23: error: reference to 'visit' is ambiguous
   63 |         for(int go:g2[visit[i]])
      |                       ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from menesinis_bilietas.cpp:1:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
menesinis_bilietas.cpp:5:5: note:                 'int visit [500001]'
    5 | int visit[500001];
      |     ^~~~~