Codeforces Round #286 (Div. 2) b. Mr Kitayuta's colorful Graph (DFS, violence)

Source: Internet
Author: User

The size of the data is small, so it's OK to enumerate the edges of each color with brute force.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<map>#include<Set>#include<vector>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<sstream>using namespacestd;#definePII pair<int,int>#defineLL Long Long intConst inteps=1e-8;Const intinf=1000000000;Const intmaxn= -+Ten;intN,m,a,b,c,q,u,v;vector<pii>VV[MAXN];intFLAG[MAXN];voidDfsintSintCO) {    if(Flag[s])return; Else{Flag[s]=1; intsiz=vv[s].size ();  for(intI=0; i<siz;i++)        {            if(vv[s][i].second==CO)            {DFS (VV[S][I].FIRST,CO); }        }        return; }}intMain () {//freopen ("In2.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);scanf"%d%d",&n,&m);  for(intI=0; i<m;i++) {scanf ("%d%d%d",&a,&b,&c);        Vv[a].push_back (Make_pair (b,c));    Vv[b].push_back (Make_pair (a,c)); } scanf ("%d",&q);  for(intI=0; i<q;i++) {scanf ("%d%d",&u,&v); intans=0;  for(intj=1; j<= -; j + +)//enumerate edges of each color{memset (flag,0,sizeof(flag));            DFS (U,J); Ans+=Flag[v]; } printf ("%d\n", ans); }    //fclose (stdin); //fclose (stdout);    return 0;}

Codeforces Round #286 (Div. 2) b. Mr Kitayuta's colorful Graph (DFS, violence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.