AtCoder Grand Contest 010

Submission #1575436

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;
	for(int i = 0; i < tree[ver].size(); i++){
		if(visto[tree[ver][i]] == 0){
			count++;
			val += sol(tree[ver][i]);
		}
	}

	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{
 		                 return 2*pesos[ver]-val;
 		           }
 	}else if(count == 0){
           return pesos[ver];
     }else{

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





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ユーザ名 vjudge1
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1611 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 AC 108 ms 7088 KB
in10.txt AC 103 ms 7088 KB
in11.txt AC 113 ms 11440 KB
in12.txt AC 118 ms 11312 KB
in13.txt AC 94 ms 12336 KB
in14.txt AC 93 ms 11568 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 WA
in2.txt AC 106 ms 7088 KB
in20.txt WA
in21.txt WA
in22.txt WA
in23.txt AC 107 ms 7088 KB
in24.txt AC 104 ms 7344 KB
in25.txt AC 1 ms 256 KB
in26.txt AC 119 ms 7088 KB
in27.txt AC 118 ms 7088 KB
in28.txt AC 1 ms 256 KB
in29.txt AC 94 ms 7088 KB
in3.txt AC 104 ms 7472 KB
in30.txt AC 1 ms 256 KB
in31.txt AC 104 ms 7344 KB
in32.txt AC 103 ms 7472 KB
in33.txt AC 103 ms 7216 KB
in34.txt AC 103 ms 7088 KB
in35.txt AC 107 ms 7088 KB
in36.txt AC 106 ms 7088 KB
in37.txt AC 2 ms 256 KB
in38.txt AC 106 ms 7088 KB
in39.txt AC 105 ms 7728 KB
in4.txt AC 103 ms 7600 KB
in40.txt AC 103 ms 7216 KB
in41.txt AC 106 ms 7088 KB
in42.txt AC 106 ms 7088 KB
in43.txt AC 106 ms 7088 KB
in44.txt WA
in45.txt AC 106 ms 7088 KB
in5.txt AC 104 ms 7728 KB
in6.txt AC 104 ms 7344 KB
in7.txt AC 95 ms 6448 KB
in8.txt AC 25 ms 1848 KB
in9.txt AC 107 ms 7088 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB