結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | Ngọc Hưng Nguyễn |
提出日時 | 2022-07-14 07:27:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 4,642 bytes |
コンパイル時間 | 1,849 ms |
コンパイル使用メモリ | 177,304 KB |
実行使用メモリ | 14,848 KB |
最終ジャッジ日時 | 2024-06-25 13:25:48 |
合計ジャッジ時間 | 3,709 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
14,848 KB |
testcase_01 | AC | 15 ms
6,940 KB |
testcase_02 | AC | 46 ms
7,936 KB |
testcase_03 | AC | 26 ms
6,944 KB |
testcase_04 | AC | 19 ms
6,944 KB |
testcase_05 | AC | 24 ms
6,940 KB |
testcase_06 | AC | 50 ms
8,960 KB |
testcase_07 | AC | 45 ms
8,704 KB |
testcase_08 | AC | 28 ms
6,940 KB |
testcase_09 | AC | 17 ms
6,940 KB |
testcase_10 | AC | 8 ms
6,944 KB |
testcase_11 | AC | 52 ms
8,960 KB |
testcase_12 | AC | 43 ms
8,320 KB |
testcase_13 | AC | 43 ms
8,320 KB |
testcase_14 | AC | 38 ms
7,808 KB |
testcase_15 | AC | 23 ms
6,940 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 25 ms
6,940 KB |
testcase_18 | AC | 50 ms
8,960 KB |
testcase_19 | AC | 47 ms
8,448 KB |
testcase_20 | AC | 49 ms
8,576 KB |
ソースコード
// -------------------------Solution by Stormgamming------------------------- // /* Author : Nguyen Ngoc Hung, Ngo Gia Tu high school */ /* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) ┏━━┓┏━━┓┏━━┓┏━━┓ ┗━┓┃┃┏┓┃┗━┓┃┗━┓┃ ┏━┛┃┃┃┃┃┏━┛┃┏━┛┃ ┃┗━┓┃┗┛┃┃┗━┓┃┗━┓ ┗━━┛┗━━┛┗━━┛┗━━┛ */ #include <bits/stdc++.h> using namespace std; /***PRAGMA***/ // #pragma GCC target ("avx2") // #pragma GCC optimization ("O2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") // #pragma GCC target ("sse4") /***TEMPLATE***/ #define DEBUG(X) {auto _X=(X); cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << endl;} #define __Storgamming__ signed main() #define count_bit(mask) __builtin_popcountll(mask) #define repdis(i,be,en,j) for(int i = (be); i<=(en); i+=j) #define rep(i,be,en) for(int i = (be); i<=(en); i++) #define repd(i,be,en) for(int i = (be); i>=(en); i--) #define trav(a,x) for(auto& a:x) #define on(i,m) (m|=(1LL<<i)) #define off(i,m) (m&=~(1LL<<i)) #define pii pair<int,int> #define pb push_back #define eb emplace_back #define inf 0x3f3f3f3f #define mp make_pair #define pii pair<int,int> #define ull unsigned long long #define ll long long #define ld long double #define int long long #define fi first #define se second #define endl "\n" #define bit(i,j) ((i>>j)&1ll) #define mask(i) (1ll<<i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define uni(a) ((a).erase(unique(all(a)),(a).end())) #define reset(x,val) memset((x),(val),sizeof(x)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) /***DEBUG CODE***/ void __print(int x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(ld x) {cerr << x;} void __print(ull x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif /***Common Functions***/ template<class T> bool ckmin(T& a, const T& b){return a>b?a=b,1:0;} template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;} template<typename num_t>void add_mod(num_t& a, const long long& b, const int& m){a=(a+b)%m;if(a>=m)a-=m;if(a<0)a+=m;} template<typename num_t>num_t gcd(num_t lhs, num_t rhs) {return !lhs?rhs:gcd(rhs%lhs,lhs);} template<typename num_t>num_t pw(num_t n, num_t k, const num_t& mod){if(k==-1)k=mod-2;num_t res=1;for(; k>0;k>>=1){if(k&1)res=1ll*res*n%mod;n=1ll*n*n%mod;}return res%mod;} const int N = (int)1e6+1; const int SIZE = (int)1e6+10; const int maxn = (int)1e5+1; const int MOD = (int)1e9+7; const int oo = (int)1e18+7; const int base = (int)311; const ld PI = 4*atan((ld)1); /***End of Template***/ int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; vector<vector<int>> a; vector<bool> f; void dfs(int u, int dad){ bool ok = false; trav(v,a[u]){ if(v!=dad){ dfs(v,u); if(f[v]==true){ ok = true; } } } if(ok==false){ f[u] = true; } } void solve(){ int n,u,v,res = 0; cin >> n; a = vector<vector<int>>(n+2,vector<int>()); f = vector<bool>(n+2,false); rep(i,2,n){ cin >> u >> v; a[u].push_back(v); a[v].push_back(u); } dfs(1,-1); rep(i,1,n){ if(f[i]==true){ res++; } } cout << res; } __Storgamming__{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); // freopen("A.inp", "r", stdin); // freopen("A.out", "w", stdout); int test = 1; while(test--){ solve(); } return 0; } /** * ʕ•ᴥ•ʔ * [storgamming] * U U */