第一种(推荐的)
#include<bits/stdc++.h> typedef long long ll; #define inf 0x7fffffff #define mem(a,b) memset( a,b,sizeof a) #define Max(a,b) a>b ? a=a : a=b #define Min(a,b) a<b ? a=a : a=b const int maxn=1e6+7; using namespace std;36 int main() { std::ios::sync_with_stdio(false); cin>>n; for(int i=0,a,b;i<n-1;i++){ cin>>a>>b; add(a,b); add(b,a); } dfs(1,0,0); dfs(s,0,0); cout<<ans+1<<endl; return 0; }
第二种
#include<bits/stdc++.h>
typedef long long ll;
#define inf 0x7fffffff
#define mem(a,b) memset( a,b,sizeof a)
#define Max(a,b) a>b ? a=a : a=b
#define Min(a,b) a<b ? a=a : a=b
const int maxn=1e6+7;
using namespace std;36 int main()
{
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=0,a,b;i<n-1;i++){
cin>>a>>b;
add(a,b);
add(b,a);
}
dfs(1,0,0);
dfs(s,0,0);
cout<<ans+1<<endl;
return 0;
}
第三种,换一种着色方案的
#include<bits/stdc++.h> typedef long long ll; #define inf 0x7fffffff #define mem(a,b) memset( a,b,sizeof a) #define Max(a,b) a>b ? a=a : a=b #define Min(a,b) a<b ? a=a : a=b const int maxn=1e6+7; using namespace std;36 int main() { std::ios::sync_with_stdio(false); cin>>n; for(int i=0,a,b;i<n-1;i++){ cin>>a>>b; add(a,b); add(b,a); } dfs(1,0,0); dfs(s,0,0); cout<<ans+1<<endl; return 0; }
综上感觉都差不多的,以后就用第一种好了;
下面是CSS贴到后台就行了


/*代码高亮*/ .syntaxhighlighter .bold { font-weight:unset !important; } .syntaxhighlighter .line { background-color: rgb(40, 43, 46)!important; } .syntaxhighlighter .line.alt2 { background-color: rgb(40, 43, 46)!important; } .syntaxhighlighter .line.alt1 { background-color: rgb(40, 43, 46)!important; } .syntaxhighlighter .comments, .syntaxhighlighter .comments a { color: rgb(129, 142, 150)!important; } .syntaxhighlighter .keyword { color: rgb(147, 199, 99)!important; font-weight: unset !important; } .syntaxhighlighter .preprocessor { color: rgb(85, 113, 130) !important; } .syntaxhighlighter .plain, .syntaxhighlighter .plain a { color: rgb(224, 226, 228)!important; } .syntaxhighlighter .color1, .syntaxhighlighter .color1 a { color: rgb(147, 199, 99)!important; } .syntaxhighlighter .string, .syntaxhighlighter .string a { color: rgb(236, 118, 0)!important; } .syntaxhighlighter .functions { color: rgb(140, 187, 173)!important; } .syntaxhighlighter .gutter .line { border-right: 2px solid rgb(147, 199, 99)!important; } .syntaxhighlighter.collapsed .toolbar { background: rgb(40, 43, 46)!important; border: none !important; border-radius: 5px !important; } .syntaxhighlighter.collapsed .toolbar a { color: rgb(147, 199, 99)!important; } .syntaxhighlighter.collapsed .toolbar a:hover { color: rgb(78, 109, 48)!important; } .syntaxhighlighter { border-radius: 5px; } /*第一种高亮结束,第二种高亮开始*/ .cnblogs_code div { background: #282b2e; } .cnblogs_code { background: #282b2e; border-radius: 5px; border: none; font-family: consolas !important; color: #fff; } .cnblogs_code_toolbar { background: #282b2e !important; } .cnblogs_code_toolbar a:hover, .cnblogs_code_toolbar a:link, .cnblogs_code_toolbar a:visited, .cnblogs_code_toolbar a:active, .cnblogs_code_toolbar a:link img, .cnblogs_code_toolbar a:visited img { background-color: #282b2e !important; border: none!important; } .cnblogs_code pre { font-family: consolas !important; padding-left: 3px; color: rgb(224, 226, 228); } .cnblogs_code span[style="color: #000000;"] , .cnblogs_code span[style="color: #ff0000;"]{ color: rgb(224, 226, 228) !important; } .cnblogs_code span[style="color: #0000ff;"]{ color: rgb(147, 199, 99)!important; } .cnblogs_code span[style="color: #800080;"]{ color: #ffd740 !important; } .cnblogs_code span[style="color: #800000;"]{ color: rgb(236, 118, 0)!important; } .cnblogs_code span[style="color: #008000;"]{ color: rgb(129, 142, 150)!important; } .cnblogs_code span[style="color: #008080;"]{ color: #afafaf!important; margin-right: 5px; } .cnblogs_code_collapse { border: none; background: #282b2e; color: rgb(147, 199, 99); } .cnblogs_code > pre { border: none !important; } .cnblogs_code > textarea { color: #fff; background: transparent; border: none; outline: none; } /*代码高亮结束*/