AtCoder Grand Contest 010

Submission #1575667

Source codeソースコード

#include<bits/stdc++.h>

using namespace std;

int init = 0;

bool sl = true;
vector<vector<int> > tree;
vector<long long> pesos;

vector<int> visto;
long long sol(int ver){

	visto[ver] = 1;

	long long count = 0;
	long long val = 0;
	vector<long long> vecVal;
	for(int i = 0; i < tree[ver].size(); i++){
		if(visto[tree[ver][i]] == 0){
			count++;
			long long v = sol(tree[ver][i]);
			vecVal.push_back(v);
			val += v;
		}
	}

	if(count == 1){

            if(val != pesos[ver]){
                     sl = false;
                     return 0;
            }else{
                  return val;
            }
     }else if(ver == init){


 		if(2*pesos[ver]-val != 0){
 		                   sl = false;
 		                   return 0;
 		           }else{
 		        	   int acomu = val;

 		        	   sort(vecVal.begin(), vecVal.end());
 						for(int i = vecVal.size()-1; i >= 0; i--){

 							if(vecVal[i] == val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}else if(vecVal[i] < val - pesos[ver] && acomu >= val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}else if(vecVal[i] > val && val - vecVal[i] >= val - pesos[ver]){
 								return 2*pesos[ver]-val;
 							}
 							acomu -= vecVal[i];
 						}
 		        	   	 sl = false;
 		        	   	 return 0;

 		           }
 	}else if(count == 0){
           return pesos[ver];
     }else{

           if(2*pesos[ver]-val < 0 || pesos[ver] > val){
                   sl = false;
                   return 0;
           }else{

	        	   if(val - pesos[ver] == 0) return 2*pesos[ver] - val;
	        	   sort(vecVal.begin(), vecVal.end());
		        	   int acomu = val;
		        	   sort(vecVal.begin(), vecVal.end());
						for(int i = vecVal.size()-1; i >= 0; i--){

							if(vecVal[i] == val - pesos[ver]){
								return 2*pesos[ver]-val;
							}else if(vecVal[i] < val - pesos[ver] && acomu >= val - pesos[ver]){
								return 2*pesos[ver]-val;
							}else if(vecVal[i] > val && val - vecVal[i] >= val - pesos[ver]){
								return 2*pesos[ver]-val;
							}
							acomu -= vecVal[i];
						}
		        	   	 sl = false;
		        	   	 return 0;
           }
     }
}





int main(){
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
         vector<int> aux;
         tree.push_back(aux);
         long long auxa;
         cin >> auxa;
         pesos.push_back(auxa);
         visto.push_back(0);
    }

    for(int i = 0; i < n-1; i++){
            int a,b;
            cin >> a >> b;
            tree[a-1].push_back(b-1);
            tree[b-1].push_back(a-1);
    }
    init = 0;
    for(int i = 0; i < n; i++){
    	if(tree[i].size() != 1){
    		init = i;
    		break;
    	}
    }



    sol(init);

    if(sl) cout << "YES";
    else cout << "NO";
}

Submission

Task問題 C - Cleaning
User nameユーザ名 vjudge2
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2765 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt
All 0 / 700 sample1.txt,sample2.txt,sample3.txt,in1.txt,in10.txt,in11.txt,in12.txt,in13.txt,in14.txt,in15.txt,in16.txt,in17.txt,in18.txt,in19.txt,in2.txt,in20.txt,in21.txt,in22.txt,in23.txt,in24.txt,in25.txt,in26.txt,in27.txt,in28.txt,in29.txt,in3.txt,in30.txt,in31.txt,in32.txt,in33.txt,in34.txt,in35.txt,in36.txt,in37.txt,in38.txt,in39.txt,in4.txt,in40.txt,in41.txt,in42.txt,in43.txt,in44.txt,in45.txt,in5.txt,in6.txt,in7.txt,in8.txt,in9.txt,sample1.txt,sample2.txt,sample3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt WA
in10.txt WA
in11.txt AC 118 ms 14640 KB
in12.txt AC 121 ms 15024 KB
in13.txt AC 100 ms 16304 KB
in14.txt AC 98 ms 15024 KB
in15.txt AC 1 ms 256 KB
in16.txt AC 1 ms 256 KB
in17.txt AC 1 ms 256 KB
in18.txt AC 1 ms 256 KB
in19.txt AC 108 ms 7856 KB
in2.txt WA
in20.txt AC 110 ms 7088 KB
in21.txt AC 110 ms 7472 KB
in22.txt AC 107 ms 7088 KB
in23.txt AC 110 ms 7088 KB
in24.txt AC 108 ms 7728 KB
in25.txt AC 1 ms 256 KB
in26.txt AC 120 ms 7088 KB
in27.txt AC 119 ms 7088 KB
in28.txt AC 1 ms 256 KB
in29.txt AC 98 ms 7472 KB
in3.txt WA
in30.txt AC 1 ms 256 KB
in31.txt AC 108 ms 7472 KB
in32.txt AC 108 ms 7088 KB
in33.txt WA
in34.txt WA
in35.txt AC 108 ms 7088 KB
in36.txt AC 110 ms 7088 KB
in37.txt AC 2 ms 256 KB
in38.txt AC 108 ms 7600 KB
in39.txt AC 107 ms 7600 KB
in4.txt WA
in40.txt AC 107 ms 7344 KB
in41.txt AC 110 ms 7088 KB
in42.txt AC 107 ms 7216 KB
in43.txt AC 108 ms 7088 KB
in44.txt AC 107 ms 7216 KB
in45.txt AC 107 ms 7216 KB
in5.txt WA
in6.txt WA
in7.txt WA
in8.txt WA
in9.txt WA
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB