Submission #2540898
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define NDEBUG #ifdef DEBUG #include "cout11.h" #undef NDEBUG #endif #include <cassert> typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> ii; typedef pair<ll,ll> llll; typedef pair<double,double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; #define sz(a) int((a).size()) #define pb push_back #define FOR(var,from,to) for(int var=(from);var<=(to);++var) #define rep(var,n) for(int var=0;var<(n);++var) #define rep1(var,n) for(int var=1;var<=(n);++var) #define repC2(vari,varj,n) for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj) #define ALL(c) (c).begin(),(c).end() #define RALL(c) (c).rbegin(),(c).rend() #define tr(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define found(s,e) ((s).find(e)!=(s).end()) #define mset(arr,val) memset(arr,val,sizeof(arr)) #define mid(x,y) ((x)+((y)-(x))/2) #define IN(x,a,b) ((a)<=(x)&&(x)<=(b)) int N; vvi nxt, d; vi rad; vi nchild; llll sub(int root){ #ifdef DEBUG //fprintf(stderr, "sub(root=%d)\n", root); #endif queue<pair<ii,vi>> q; q.push(make_pair(llll(1,nchild[root]), vi(1, root))); // (color,dup), vi vi visited(N, 0); int maxcolor = 0; ll maxdup = 0; while (!q.empty()) { int color = q.front().first.first; ll dup = q.front().first.second; maxcolor = max(maxcolor, color); vi layer = q.front().second; int maxch = 1; for(int u:layer){ visited[u] = 1; maxch = max(maxch, nchild[root]-1); } q.pop(); //cerr << "L" << color << " x " << dup << " : " << layer << endl; vi sublayer; // int maxch = 1; for(int u:layer){ for(int v:nxt[u]){ if (visited[v]) continue; sublayer.pb(v); // maxch = max(maxch, nchild[v]); } } maxdup = max(maxdup, dup*maxch); if (sublayer.size() > 0) { q.push(make_pair(llll(color+1,dup*maxch), sublayer)); } } return llll(maxcolor,maxdup); } llll sub2(int u, int v){ #ifdef DEBUG fprintf(stderr, "sub2(%d,%d)\n", u,v); #endif queue<pair<ii,vi>> q; vi v0 { u, v}; int x= 2;//nchild[u] + nchild[v]; q.push(make_pair(llll(1,x), v0)); // (color,dup), vi vi visited(N, 0); int maxcolor = 0; ll maxdup = 0; while (!q.empty()) { int color = q.front().first.first; ll dup = q.front().first.second; maxcolor = max(maxcolor, color); vi layer = q.front().second; int maxch = 1; for(int u:layer){ visited[u] = 1; maxch = max(maxch, nchild[u]-1); } q.pop(); #ifdef DEBUG cerr << "L" << color << " x " << dup << " : " << layer << endl; #endif vi sublayer; for(int u:layer){ for(int v:nxt[u]){ if (visited[v]) continue; sublayer.pb(v); // maxch = max(maxch, nchild[v]); } } maxdup = max(maxdup, dup*maxch); if (sublayer.size() > 0) { q.push(make_pair(llll(color+1,dup*maxch), sublayer)); } } return llll(maxcolor,maxdup); } void solve(){ d.assign(N, vi(N, N*2)); rep(i,N) d[i][i] = 0; rep(u,N){ for (int v:nxt[u]) d[u][v] = d[v][u] = 1; } rep(k,N) rep(i,N) rep(j,N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]); rad.assign(N, 0); nchild.assign(N, 0); rep(i,N) { rep(j,N) rad[i] = max(rad[i], d[i][j]); nchild[i] = nxt[i].size(); } #ifdef DEBUG rep(i,N) { rep(j,N) { fprintf(stderr, " %2d", d[i][j]); } cerr << endl; } cerr << "rad: " << rad << endl; #endif llll ans(0x7fffffffffffffffLL, 0x7fffffffffffffffLL); set<ii> visited_edges; rep(root, N){ llll score = sub(root); ans = min(ans, score); for(int v: nxt[root]){ ii e(min(root,v), max(root,v)); if (!found(visited_edges, e)){ visited_edges.insert(e); llll score2 = sub2(root, v); ans = min(ans, score2); } } } printf("%lld %lld\n", ans.first, ans.second); } int main() { cin >>N; nxt.assign(N, vi()); rep(i,N-1){ int a,b; cin>>a>>b; --a;--b; nxt[a].pb(b); nxt[b].pb(a); } solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Isomorphism Freak |
User | naoya_t |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 4717 Byte |
Status | WA |
Exec Time | 5 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1100 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt, s4.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, 75.txt, 76.txt, 77.txt, 78.txt, 79.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, 96.txt, 97.txt, 98.txt, 99.txt, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 4 ms | 256 KB |
02.txt | WA | 4 ms | 256 KB |
03.txt | WA | 4 ms | 256 KB |
04.txt | WA | 4 ms | 256 KB |
05.txt | WA | 4 ms | 256 KB |
06.txt | WA | 4 ms | 256 KB |
07.txt | AC | 5 ms | 256 KB |
08.txt | AC | 5 ms | 256 KB |
09.txt | AC | 5 ms | 256 KB |
10.txt | AC | 5 ms | 256 KB |
11.txt | AC | 5 ms | 256 KB |
12.txt | AC | 5 ms | 256 KB |
13.txt | AC | 4 ms | 256 KB |
14.txt | AC | 3 ms | 256 KB |
15.txt | AC | 4 ms | 256 KB |
16.txt | AC | 4 ms | 256 KB |
17.txt | AC | 5 ms | 256 KB |
18.txt | AC | 5 ms | 256 KB |
19.txt | AC | 5 ms | 256 KB |
20.txt | AC | 3 ms | 256 KB |
21.txt | AC | 4 ms | 256 KB |
22.txt | AC | 4 ms | 256 KB |
23.txt | AC | 4 ms | 256 KB |
24.txt | AC | 4 ms | 256 KB |
25.txt | AC | 4 ms | 256 KB |
26.txt | AC | 4 ms | 256 KB |
27.txt | WA | 5 ms | 256 KB |
28.txt | WA | 5 ms | 256 KB |
29.txt | WA | 5 ms | 256 KB |
30.txt | WA | 3 ms | 256 KB |
31.txt | WA | 3 ms | 256 KB |
32.txt | WA | 4 ms | 256 KB |
33.txt | WA | 4 ms | 256 KB |
34.txt | AC | 4 ms | 256 KB |
35.txt | WA | 4 ms | 256 KB |
36.txt | WA | 4 ms | 256 KB |
37.txt | WA | 3 ms | 256 KB |
38.txt | WA | 3 ms | 256 KB |
39.txt | AC | 3 ms | 256 KB |
40.txt | AC | 3 ms | 256 KB |
41.txt | AC | 4 ms | 256 KB |
42.txt | AC | 4 ms | 256 KB |
43.txt | AC | 4 ms | 256 KB |
44.txt | AC | 4 ms | 256 KB |
45.txt | AC | 5 ms | 256 KB |
46.txt | AC | 4 ms | 256 KB |
47.txt | AC | 4 ms | 256 KB |
48.txt | WA | 4 ms | 256 KB |
49.txt | AC | 4 ms | 256 KB |
50.txt | AC | 4 ms | 256 KB |
51.txt | AC | 4 ms | 256 KB |
52.txt | AC | 4 ms | 256 KB |
53.txt | WA | 4 ms | 256 KB |
54.txt | AC | 4 ms | 256 KB |
55.txt | WA | 4 ms | 256 KB |
56.txt | AC | 4 ms | 256 KB |
57.txt | WA | 5 ms | 256 KB |
58.txt | WA | 5 ms | 256 KB |
59.txt | WA | 5 ms | 256 KB |
60.txt | AC | 3 ms | 256 KB |
61.txt | WA | 3 ms | 256 KB |
62.txt | AC | 3 ms | 256 KB |
63.txt | WA | 4 ms | 256 KB |
64.txt | WA | 4 ms | 256 KB |
65.txt | AC | 4 ms | 256 KB |
66.txt | AC | 4 ms | 256 KB |
67.txt | WA | 4 ms | 256 KB |
68.txt | AC | 5 ms | 256 KB |
69.txt | WA | 5 ms | 256 KB |
70.txt | WA | 3 ms | 256 KB |
71.txt | WA | 3 ms | 256 KB |
72.txt | WA | 4 ms | 256 KB |
73.txt | WA | 3 ms | 256 KB |
74.txt | WA | 4 ms | 256 KB |
75.txt | WA | 4 ms | 256 KB |
76.txt | AC | 4 ms | 256 KB |
77.txt | WA | 5 ms | 256 KB |
78.txt | WA | 5 ms | 256 KB |
79.txt | WA | 4 ms | 256 KB |
80.txt | WA | 3 ms | 256 KB |
81.txt | AC | 3 ms | 256 KB |
82.txt | WA | 4 ms | 256 KB |
83.txt | WA | 3 ms | 256 KB |
84.txt | AC | 4 ms | 256 KB |
85.txt | AC | 4 ms | 256 KB |
86.txt | WA | 4 ms | 256 KB |
87.txt | AC | 5 ms | 256 KB |
88.txt | WA | 5 ms | 256 KB |
89.txt | WA | 4 ms | 256 KB |
90.txt | AC | 3 ms | 256 KB |
91.txt | AC | 3 ms | 256 KB |
92.txt | WA | 3 ms | 256 KB |
93.txt | AC | 1 ms | 256 KB |
94.txt | AC | 1 ms | 256 KB |
95.txt | WA | 1 ms | 256 KB |
96.txt | AC | 1 ms | 256 KB |
97.txt | AC | 1 ms | 256 KB |
98.txt | WA | 1 ms | 256 KB |
99.txt | WA | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | WA | 1 ms | 256 KB |
s4.txt | AC | 1 ms | 256 KB |