div 2
200pt:水题,用stringstream方便多了
550pt:水题,按题意模拟就行,想清楚了再写,要不然越改越乱!
1100pt:我是个二百五!!树形dp,dp你妹啊!把所有的的dis[]*2累加,然后找到一条最长的路,把那条路作为最后走的,减掉回来的距离就可以了!我还在那里想个毛树形dp,叉!
View Code
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define REP(i, n) for(i = 0; i < n; ++i) #define FOR(i, l, h) for(i = l; i <= h; ++i) #define FORD(i, h, l) for(i = h; i >= l; --i) #define L(x) x << 1 #define R(x) x << 1 | 1 #define MID(l, r) (l + r) >> 1 using namespace std; class PowerOutage { public: int dfs(int r, vector<int> fr, vector<int> to, vector<int> d) { int ans = 0, i, l = fr.size(); REP(i, l) { if(fr[i] == r) { ans = max(ans, d[i] + dfs(to[i], fr, to, d)); } } return ans; } int estimateTimeOut(vector <int> fr, vector <int> to, vector <int> d) { int i, l = fr.size(), ans = 0; REP(i, l) ans += d[i]*2; ans -= dfs(0, fr, to, d); return ans; } };