Submission #2489568


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<int> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	int from;
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

int main(){
	int n,x; SCD2(n,x);
	int h[102] = {};
	int ans = 100000;
	FORq(i,1,n){
		int hn; SCD(hn);
		h[i] = hn;
	}
	
	struct Vertex v[102];
	REP(i,n-1){
		int a,b; SCD2(a,b);
		v[a].edges_to.PB(b);
		v[a].edges_cost.PB(1);
		v[b].edges_to.PB(a);
		v[b].edges_cost.PB(1);
	}
	
	FORq(i,1,n){ // start vertex i
		FORq(l,1,n){
			v[l].done = false;
			v[l].cost = 0;
		}
		
		queue<int>Q; Q.push(i);
		set<int>visited;
		while(!Q.empty()){
			
			int now = Q.front(); Q.pop();
			REP(j,v[now].edges_to.size()){
				int to = v[now].edges_to[j];
				if (v[to].done) continue;
				v[to].cost = v[now].cost + 1;
				v[to].from = now;
				Q.push(to);
				v[to].done = true;
			}
		}
		
		int nans = 0;
		FORq(k,1,n){
			if (h[k] == 0) continue;
			int p = k;
			while(p != i){
				if (visited.count(p) == 0) {
					visited.insert(p);
					nans += 2;
				}
				
				p = v[p].from;
			}
		}
		
		ans = min(ans,nans);
		
	}
		
	PRINTD(ans);	
	return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User Lithium
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2179 Byte
Status WA
Exec Time 5 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n,x; SCD2(n,x);
                    ^
./Main.cpp:46:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int hn; SCD(hn);
                  ^
./Main.cpp:52:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int a,b; SCD2(a,b);
                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 13
WA × 7
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask1_line01.txt AC 1 ms 256 KB
subtask1_line02.txt WA 4 ms 256 KB
subtask1_line03.txt WA 2 ms 256 KB
subtask1_line04.txt WA 4 ms 256 KB
subtask1_line05.txt AC 5 ms 256 KB
subtask1_line06.txt AC 1 ms 256 KB
subtask1_random01.txt AC 3 ms 256 KB
subtask1_random02.txt WA 2 ms 256 KB
subtask1_random03.txt AC 2 ms 256 KB
subtask1_random04.txt WA 3 ms 256 KB
subtask1_random05.txt AC 3 ms 256 KB
subtask1_random06.txt WA 3 ms 256 KB
subtask1_random07.txt AC 3 ms 256 KB
subtask1_random08.txt WA 3 ms 256 KB
subtask1_special01.txt AC 1 ms 256 KB
subtask1_special02.txt AC 2 ms 256 KB
subtask1_special03.txt AC 2 ms 256 KB
subtask1_special04.txt AC 2 ms 256 KB