比赛 |
不平凡的世界 |
评测结果 |
AWEEEWEEEE |
题目名称 |
不平凡的许愿树 |
最终得分 |
10 |
用户昵称 |
shooter |
运行时间 |
0.799 s |
代码语言 |
C++ |
内存使用 |
0.39 MiB |
提交时间 |
2015-11-05 11:37:55 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<vector>
- #define mod 338
- using namespace std;
- int jic(int x){
- int ans=1;
- for(int i=2;i<=x;i++)
- ans*=i;
- return ans;
- }
- int comb(int m,int n){
- return ((jic(n))/(jic(m)*jic(n-m)));
- }
- struct node{
- node *father;
- vector<node*>child;
- node(){
- child.clear();
- this->father=NULL;
- }
- }s[5010];
- void addnode(int x,int y){
- if(s[y].father==NULL){
- s[y].father=&s[x];
- s[x].child.push_back(&s[y]);
- }
- else{
- if(s[x].father==NULL){
- s[x].father=&s[y];
- s[y].child.push_back(&s[x]);
- }
- }
- }
- int main(){
- freopen("hopetree.in","r",stdin);
- freopen("hopetree.out","w",stdout);
- int n;
- cin>>n;
- int u,v;
- for(int i=1;i<=n-1;i++){
- cin>>u>>v;
- addnode(u,v);
- }
- int sum=0;
- for(int i=1;i<=n;i++){
- if(s[i].father==NULL)
- sum+=comb(3,s[i].child.size());
- else
- sum+=comb(3,s[i].child.size()+1);
- sum=sum%mod;
-
- }
- int a1=sum%mod+1;
- int a2=(sum+233)%mod+1;
- cout<<a1<<" "<<a2;
- return 0;
- fclose(stdin);
- fclose(stdout);
- }