2333...
Due to the small number of TC entries and the constant FST, I dropped to div2.
It's okay to go back to div1 ..
250
Question
500
Question ..
Just extend the BFS directly.
Pay attention to the heavy judgment. I also launched it with Kanto ..
1000
This question is understood as incorrect .. I told you why someone else's code looks wrong.
However, it is very easy to answer a question.
Which leaf nodes are burned by binary enumeration?
Then for each method
Minimum Short Circuit
Calculate the shortest path, enumeration side
Assume that the two nodes of the edge are u and the V weight is W.
The greatest (DIS [u] + dis [v] + W)/2 is the time when the data is burned out.
Why?
Assume that an edge is finally burned.
One is U, and V is burned by other nodes.
One is that u is burned by V.
First, set dis [u]> dis [v]
The answer is (L-(DIS [u]-Dis [v])/2 + dis [u] = (DIS [u] + dis [v] + l)/2
Second
Dis [v] + L = dis [u]
So the same dis [u] = (DIS [v] + L + dis [u])/2
Both of them can use this representation.
Then we will not divide it by 2 for convenience.
struct node { int v, w; node () {} node (int _v, int _w) {v = _v; w = _w;}};vector<node>g[22];int ind[22], lea[22], pos[22], d[22], vis[22], q[1111];set<int> s;class CandleTimerEasy{public: int differentTime(vector <int> A, vector <int> B, vector <int> len) { int n = A.size() + 1; for(int i = 0; i < n; i++) g[i].clear(); memset(ind, 0, sizeof(ind)); for(int i = 0; i < n - 1; i++) { g[A[i]].push_back(node(B[i], len[i])); g[B[i]].push_back(node(A[i], len[i])); ++ind[A[i]]; ++ind[B[i]]; } s.clear(); int cnt = 0; memset(pos, -1, sizeof(pos)); for(int i = 0; i < n; i++) { if(ind[i] == 1) { lea[cnt] = i; pos[i] = cnt; cnt++; } } for(int sta = 1; sta < (1 << cnt); sta ++) { int h = 0, t = 0; for(int i = 0; i < n; i++) { d[i] = INF; vis[i] = 0; if(pos[i] != -1) { if(sta & (1 << pos[i])) { q[t++] = i; d[i] = 0; vis[i] = 1; } } } while(h < t) { int u = q[h++]; vis[u] = 0; for(int i = 0; i < g[u].size(); i++) { int v = g[u][i].v; int w = g[u][i].w; if(d[u] + w < d[v]) { d[v] = d[u] + w; if(!vis[v]) { q[t++] = v; vis[v] = 1; } } } } int mx = 0; for(int i = 0; i < n - 1; i++) mx = max(mx, d[A[i]] + d[B[i]] + len[i]); s.insert(mx); } return (int)s.size(); }}
SRM 638 div2