QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346838#7936. Eliminate Treekevinshan#Compile Error//C++171.5kb2024-03-09 02:28:392024-03-09 02:28:40

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 02:28:40]
  • 评测
  • [2024-03-09 02:28:39]
  • 提交

answer

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

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second

#define FOR(i,a,b) for(int i=a;i<b;i++) 
#define For(i,a) FOR(i,0,a)
#define trav(a,b) for(auto& a:b)
#define pi pair<int,int>
#define vi vector<int>

const int MX = 2e5+5;
const int MOD = 1e9+7;
vi adj[MX];
int dp[MX][2];

void dfs(int n, int p) {
    if(adj[n].size()==1) { // make sure root size != 1
        dp[n][0]=0;
        dp[n][1]=2;
        return;    
    }
    trav(x,adj[n]) if(x!=p) {
        dfs(x,n);
    }
    int sum1 = 0;
    int tmp = MOD;
    trav(x,adj[n]) if(x!=p) {
        sum1 += dp[x][1];
        tmp = min(tmp, dp[x][0]-dp[x][1]);
    }
    dp[n][0] = sum1;
    dp[n][1] = sum1 + 1 + tmp;
    dp[n][1] = min(dp[n][1], dp[n][0]+2);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;cin>>n;
    For(i,n-1) {
        int u,v;cin>>u>>v;
        u--;v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if(n==1) {
        cout << 2 << '\n';
    } else if(n==2) {
        cout << 1 << '\n';
    } else {
        For(i,n)For(j,2)dp[i][j]=MOD;
        For(i,n) if(adj[i].size() > 1) {
            dfs(i,i);
            cout << dp[i][1] << endl;
            return;
        }
        assert(false);
    }

    
}


Details

answer.code: In function ‘int main()’:
answer.code:63:13: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
   63 |             return;
      |             ^~~~~~
answer.code:44:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:45:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~