Submission #1801806
Source Code Expand
#include "bits/stdc++.h" using namespace std; #define RESIDUE(u,v) (capacity[u][v] - flow[u][v]) #define RCOST(u,v) (cost[u][v] + h[u] - h[v]) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define LL long long void disp(vector<int> v){ for(int i=0;i<v.size();i++){ cout << v[i] << " "; } cout<<endl; } template <typename T> class undigraph { public: struct edge{ int from; int to; T cost; }; vector< vector<int> > v; vector<edge> edges; int n; undigraph(int n){ v.resize(n); } void add(int from,int to,T cost = 1){ v[from].push_back(edges.size()); v[to].push_back(edges.size()); edges.push_back({from, to, cost}); } }; template <typename T> vector <T> dijkstra(const undigraph<T> &g, int start) { vector<T> dist(g.n, numeric_limits<T>::max()); priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > s; dist[start] = 0; s.emplace(dist[start], start); while(!s.empty()){ int expected = s.top().first; int base = s.top().second; if(expected != dist[base]){ continue; } s.pop(); for(int id:g.v[base]){ auto &e = g.edges[id]; int to = base ^ e.from ^ e.to; if(dist[base] + e.cost < dist[to]){ dist[to] = dist[base] + e.cost; s.emplace(dist[to],to); } } } return dist; } #define MAX_N 100000 int par[MAX_N],rnk[MAX_N]; void init(int n){ REP(i,n){ par[i]=i; rnk[i]=0; } } int root(int x){ return par[x]==x?x:par[x]=root(par[x]); } bool same(int x,int y){ return root(x)==root(y); } void unite(int x,int y){ x=root(x); y=root(y); if(x==y) return; if(rnk[x]<rnk[y]){ par[x]=y; }else{ par[y]=x; if(rnk[x]==rnk[y]) rnk[x]++; } } vector<vector<int>> v; int main(){ int n,m,k,l; cin>>n>>m; v.resize(m); init(n); REP(i,n){ cin>>k; REP(j,k){ cin>>l; l--; v[l].push_back(i); } } REP(i,m){ FOR(j,1,v[i].size()){ unite(v[i][0],v[i][j]); } } REP(i,n){ if(!same(0,i)){ cout<<"NO"<<endl; return 1; } } cout<<"YES"<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | penpenpen |
Language | C++ (GCC 5.4.1) |
Score | 0 |
Code Size | 2281 Byte |
Status | CE |
Compile Error
./Main.cpp: In member function ‘void undigraph<T>::add(int, int, T)’: ./Main.cpp:38:21: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 edges.push_back({from, to, cost}); ^ ./Main.cpp: In function ‘std::vector<_Tp> dijkstra(const undigraph<T>&, int)’: ./Main.cpp:56:16: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11 for(int id:g.v[base]){ ^ ./Main.cpp:57:13: error: ISO C++ forbids declaration of ‘e’ with no type [-fpermissive] auto &e = g.edges[id]; ^ ./Main.cpp:58:25: error: request for member ‘from’ in ‘e’, which is of non-class type ‘int’ int to = base ^ e.from ^ e.to; ^ ./Main.cpp:58:34: error: request for member ‘to’ in ‘e’, which is of non-class type ‘int’ int to = base ^ e.from ^ e.to; ^ ./Main.cpp:59:25: error: request for member ‘cost’ in ‘e’, which is of non-class type ‘int’ if(dist[b...