CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:okkokko
Submission time:2021-10-14 18:50:19 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:111:5: error: expected ';' before 'return'
     return 0;
     ^~~~~~

Code

#include <iostream>
#include <map>
#include <bits/stdc++.h>
using namespace std;
using std::map;


map<int,int> *koneet;
long total = 0;
int tries = 0;

map<int,int> Crossroads(int kone,int source,int sourceSpeed) {
	tries+=1;
	//if (tries>300){cout << "x";return yhteydet;}
	
	map<int,int> &ko = koneet[kone];
	int haaSize = ko.size()-1;
	
	if(haaSize==0){
	
		//return map<int,int> {{sourceSpeed,1}};
		map<int,int> a;
		a[sourceSpeed]=1;
		return a;
	}
	
	if (source==0){
		haaSize+=1;
	}
	
	vector<map<int,int>> haarat(haaSize+1);  //=new map<int,int>[haaSize+1];
	int i_k = 0;
	for (auto &item : ko){
		if (item.first !=source){
			haarat[i_k]=Crossroads(item.first,kone,item.second);
			//delete koneet[item.first];
			i_k+=1;
		}
	}
	long addTotalHalf = 0;
	map<int,int> yhteydet;
	yhteydet[sourceSpeed] = 1;
	
	//for (int i = 0; i<haaSize; i++){
	for (auto &item1 : haarat){
		for (auto &item : item1){
			int a = std::min(item.first, sourceSpeed);
			yhteydet.emplace(a,0);
			yhteydet[a]+=item.second;
			addTotalHalf+=2*item.second*item.first;
		}
	}
	
	if (haaSize>1){
		long addTotalHalf = 0;
		map<int,int> yhtyhaara;
		
		//for (int i = 0; i<haaSize; i++){
		for (auto &item1 : haarat){
			for (auto &item : item1){
				yhtyhaara.emplace(item.first,0);
				yhtyhaara[item.first]+=item.second;
			}
		}
		//int yhSize = yhtyhaara.size();

		int ta = 0;
		int tb = 0;
		for (auto &item : yhtyhaara){
			tb+=item.second;
		}
		for (auto &item : yhtyhaara){
			ta+=item.first*item.second;
			tb-=item.second;
			addTotalHalf+=(ta+tb*item.first)*item.second;
		}
		for (auto &item1 : haarat){
			int ta = 0;
			int tb = 0;
			for (auto &item : item1){
				tb+=item.second;
			}
			for (auto &item : item1){
				ta+=item.first*item.second;
				tb-=item.second;
				addTotalHalf-=(ta+tb*item.first)*item.second;
			}
		}
		//addTotal+=addTotalHalf/2;
		}
	
	total+=addTotalHalf;
	//delete[] haarat;
	return yhteydet;
}

int main(){
	int n;
	cin >> n;
	koneet =new map<int,int>[n+1];
	for (int i = 0; i<n; i++){
		int c0,c1,c2;
		cin >> c0 >> c1 >> c2;
		koneet[c0][c1]=c2;
		koneet[c1][c0]=c2;
	}

	Crossroads(1,0,0);
	cout << total//2;

    return 0;
}