Submission #8610394


Source Code Expand

Copy
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

vector<int> g[100010]; map<pair<int,int>,int> mp;
int cnt[100010]={},ma=0,ans[100010];
void dfs(int v,int pre,int col){
    if(pre!=-1)ans[mp[{v,pre}]]=col; int nxt=0;
    for(int to:g[v])if(to!=pre){
        if(nxt==col)nxt++;
        dfs(to,v,nxt); nxt++;
    }
}

int main(){
    int n; scanf("%d",&n);
    rep(i,0,n-1){
        int a,b; scanf("%d%d",&a,&b); a--; b--;
        g[a].push_back(b); g[b].push_back(a);
        cnt[a]++; cnt[b]++; mp[{a,b}]=mp[{b,a}]=i;
    }
    rep(i,0,n)chmax(ma,cnt[i]);
    printf("%d\n",ma);
    dfs(0,-1,-1);
    rep(i,0,n-1)printf("%d\n",ans[i]+1);
    return 0;
}

Submission Info

Submission Time
Task D - Coloring Edges on Tree
User TKO
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1116 Byte
Status AC
Exec Time 175 ms
Memory 19584 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d",&n);
                          ^
./Main.cpp:27:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         int a,b; scanf("%d%d",&a,&b); a--; b--;
                                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 11-small-01.txt, 11-small-02.txt, 11-small-03.txt, 11-small-04.txt, 11-small-05.txt, 11-small-06.txt, 11-small-07.txt, 11-small-08.txt, 11-small-09.txt, 11-small-10.txt, 31-large-01.txt, 31-large-02.txt, 31-large-03.txt, 31-large-04.txt, 31-large-05.txt, 41-min-01.txt, 51-max-01.txt, 61-path-01.txt, 61-path-02.txt, 61-path-03.txt, 71-star-01.txt, 71-star-02.txt, 71-star-03.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 3 ms 2560 KB
00-sample-02.txt AC 3 ms 2560 KB
00-sample-03.txt AC 3 ms 2560 KB
11-small-01.txt AC 3 ms 2560 KB
11-small-02.txt AC 3 ms 2688 KB
11-small-03.txt AC 3 ms 2688 KB
11-small-04.txt AC 3 ms 2688 KB
11-small-05.txt AC 3 ms 2688 KB
11-small-06.txt AC 3 ms 2688 KB
11-small-07.txt AC 3 ms 2688 KB
11-small-08.txt AC 3 ms 2688 KB
11-small-09.txt AC 3 ms 2688 KB
11-small-10.txt AC 3 ms 2688 KB
31-large-01.txt AC 14 ms 4352 KB
31-large-02.txt AC 98 ms 12800 KB
31-large-03.txt AC 33 ms 6272 KB
31-large-04.txt AC 28 ms 5888 KB
31-large-05.txt AC 70 ms 10112 KB
41-min-01.txt AC 3 ms 2560 KB
51-max-01.txt AC 175 ms 19328 KB
61-path-01.txt AC 76 ms 19584 KB
61-path-02.txt AC 18 ms 6912 KB
61-path-03.txt AC 22 ms 7808 KB
71-star-01.txt AC 16 ms 4608 KB
71-star-02.txt AC 106 ms 14588 KB
71-star-03.txt AC 44 ms 7552 KB