結果

問題 No.812 Change of Class
ユーザー smiken_61smiken_61
提出日時 2019-04-13 16:44:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 210 ms / 4,000 ms
コード長 8,702 bytes
コンパイル時間 3,422 ms
コンパイル使用メモリ 155,088 KB
実行使用メモリ 12,332 KB
最終ジャッジ日時 2023-09-03 14:49:34
合計ジャッジ時間 9,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
9,872 KB
testcase_01 AC 10 ms
7,144 KB
testcase_02 AC 31 ms
8,360 KB
testcase_03 AC 63 ms
10,316 KB
testcase_04 AC 55 ms
10,020 KB
testcase_05 AC 210 ms
11,076 KB
testcase_06 AC 197 ms
10,792 KB
testcase_07 AC 5 ms
7,020 KB
testcase_08 AC 4 ms
6,828 KB
testcase_09 AC 175 ms
11,260 KB
testcase_10 AC 177 ms
11,384 KB
testcase_11 AC 13 ms
8,232 KB
testcase_12 AC 105 ms
10,464 KB
testcase_13 AC 3 ms
6,716 KB
testcase_14 AC 4 ms
6,684 KB
testcase_15 AC 123 ms
9,596 KB
testcase_16 AC 10 ms
6,892 KB
testcase_17 AC 107 ms
9,840 KB
testcase_18 AC 79 ms
9,004 KB
testcase_19 AC 93 ms
9,360 KB
testcase_20 AC 187 ms
11,080 KB
testcase_21 AC 80 ms
8,888 KB
testcase_22 AC 36 ms
8,012 KB
testcase_23 AC 8 ms
7,060 KB
testcase_24 AC 12 ms
6,972 KB
testcase_25 AC 29 ms
7,568 KB
testcase_26 AC 147 ms
10,404 KB
testcase_27 AC 131 ms
9,904 KB
testcase_28 AC 90 ms
9,364 KB
testcase_29 AC 23 ms
7,244 KB
testcase_30 AC 115 ms
9,760 KB
testcase_31 AC 98 ms
9,236 KB
testcase_32 AC 44 ms
8,180 KB
testcase_33 AC 121 ms
10,148 KB
testcase_34 AC 11 ms
6,956 KB
testcase_35 AC 23 ms
7,388 KB
testcase_36 AC 10 ms
6,944 KB
testcase_37 AC 52 ms
8,120 KB
testcase_38 AC 7 ms
7,244 KB
testcase_39 AC 55 ms
8,264 KB
testcase_40 AC 15 ms
7,156 KB
testcase_41 AC 6 ms
7,116 KB
testcase_42 AC 111 ms
9,488 KB
testcase_43 AC 23 ms
8,584 KB
testcase_44 AC 76 ms
8,736 KB
testcase_45 AC 10 ms
6,960 KB
testcase_46 AC 21 ms
8,468 KB
testcase_47 AC 74 ms
8,748 KB
testcase_48 AC 83 ms
9,140 KB
testcase_49 AC 22 ms
7,524 KB
testcase_50 AC 4 ms
6,708 KB
testcase_51 AC 24 ms
7,584 KB
testcase_52 AC 47 ms
8,724 KB
testcase_53 AC 15 ms
7,200 KB
testcase_54 AC 13 ms
7,120 KB
testcase_55 AC 59 ms
10,436 KB
testcase_56 AC 70 ms
11,260 KB
testcase_57 AC 75 ms
11,460 KB
testcase_58 AC 39 ms
9,132 KB
testcase_59 AC 83 ms
12,332 KB
testcase_60 AC 3 ms
6,672 KB
testcase_61 AC 3 ms
6,812 KB
testcase_62 AC 3 ms
6,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

     #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-10)
                                          
    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}
                                            
                                            };
                                            
                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}
                                            		
                                            
                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}
                                            		
                                            
                                            };
                                            

                      
                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }
                                 
                                int gcd(int v,int b){
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }
                 
                            
                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {   
    return {l.first+r.first,l.second+r.second};                                    
}    
pa operator-(const pa & l,const pa & r) {   
    return {l.first-r.first,l.second-r.second};                                    
}  
                                
                int pr[1200010];
                int inv[1200010];
                
                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }

                
    			int comb(int nn,int rr){
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}
                
                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }
                
              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;            
                 //sort(ve.begin(),ve.end(),greater<int>());
    
       
       
                               //----------------kokomade tenpure------------


vector<int> G[100020];

int dis[100020];
int ch(int r){
	int d=-1;
	r--;
	//cout<<r<<endl;
	for(int i=0;i<25;i++)if(r&(1<<i)){
		d=i;
	}
	return d+1;
}

 signed main(){
 	

    	       cin.tie(0);
   			ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 	for(int i=0;i<m;i++){
 		int y,yy;
 		cin>>y>>yy;
 			G[y].pb(yy);
 		G[yy].pb(y);
 	}
 	int q;
 	cin>>q;
 	for(int er=0;er<q;er++){
 		int y;
 		cin>>y;
 		for(int i=1;i<=n;i++)dis[i]=-1;
 		
 		queue<pa> qu;
 			qu.push({y,0});
 		
 		while(qu.size()){
 			pa z=qu.front();
 			qu.pop();
 			if(dis[z.first]>=0) continue;
 			dis[z.first]=z.second;
 			
 			for(auto v:G[z.first]){
 				if(dis[v]>=0) continue;
 					qu.push({v,z.second+1});
 			}
 		}
 		int cnt=0;
 		int ma=1;
 		for(int i=1;i<=n;i++)if(i!=y){
 			if(dis[i]>0){
 				cnt++;
 				ma=max(ma,dis[i]);
 			}
 		}
 		
 		cout<<cnt<<" "<<ch(ma)<<endl;
 	}
 	
 	
 	

 	return 0;
  }
  
0