Example #1
0
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int counter=0,n,i,j,l;
    VI vis;
    string str,str1,str2;
    vector <string> v;
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>str;
        v.PB(str);
        str1=getdomain(str);
        str2=getlogin(str,str1);
        mp[MP(str2,str1)].PB(i);
    }
    VI v1;
    vis.resize(n,0);
    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            counter++;
            str=v[i];
            str1=getdomain(str);
            str2=getlogin(str,str1);
            v1=mp[MP(str2,str1)];
            l=v1.size();
            for(j=0;j<l;j++)
                vis[v1[j]]=1;
        }
    }   
    cout <<counter<<"\n";
    vis.assign(n,0);
    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            str=v[i];
            str1=getdomain(str);
            str2=getlogin(str,str1);
            v1=mp[MP(str2,str1)];
            l=v1.size();
            cout <<l;
            for(j=0;j<l;j++)
            {
                vis[v1[j]]=1;
                cout <<" "<<v[v1[j]];
            }
            cout <<"\n";
        }
    }   
    return 0;
}
Example #2
0
   bool augmenting_path_bfs(int src, int dst, int mincap = 0) {
      sp_par.assign(N, -1);
      sp_D.assign(N, -1);

      sp_D[src] = 0;
      queue<int> q;
      q.push(src);
      while (!q.empty()) {
         int cur = q.front();
         q.pop();
         for (int j = 0; j < (int) adj[cur].size(); ++j) {
            int e = adj[cur][j];
            int v = edges[e].v;
            if (sp_D[v] < 0 && edges[e].cap - edges[e].flow > mincap) {
               sp_D[v] = sp_D[cur] + 1;
               sp_par[v] = e;
               q.push(v);
            }
         }
      }
      return sp_D[dst] >= 0;
   }
int main(){
	int ncases;
	int u, v, w, V, E;
	scanf("%d",&ncases);
	while(ncases--){
		scanf("%d",&V);
		AdjList.assign(V, VII());
		
		for(int i=1; i<V; i++){
			scanf("%d %d %d",&u, &v, &w);
			AdjList[u-1].push_back(make_pair(v-1,w));
			AdjList[v-1].push_back(make_pair(u-1,w));	
		}
		dfs_num.assign(V, -1);
		maxlen = -1;
		dfs(0,0);
		dfs_num.assign(V, -1);
		maxlen = -1;
		//printf("end %d\n",end);
		dfs(end,0);
		printf("%d\n",maxlen);
	}
  	return 0;
}
Example #4
0
   int dinic(int s, int t) {
      N = int(adj.size());
      for (int j = 0; j < (int) edges.size(); ++j)
         edges[j].flow = 0;

      VI path;
      int res = 0;

      while ( augmenting_path_bfs(s, t) ) {
   		last_edge.assign(N, 0);
   		while (true) {
   		   int cfp = update_flow_dfs(s, t);
   		   if (cfp <= 0) break;
   		   res += cfp;
   		}
      }
   return res;
   }
Example #5
0
File: H.cpp Project: lapl/Maratona
void initSet(int n) {
	pset.assign(n,0);
	REP(i,n) pset[i]=i;
}