Submission #76113

#TimeUsernameProblemLanguageResultExecution timeMemory
76113cubecube1000스파이 (JOI13_spy)C++14
100 / 100
576 ms83388 KiB
#include<bits/stdc++.h> #define x first #define y second using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll, ll> pll; const ll MAX=2005; const ll INFint=0x3f3f3f3f; const ll INFLL=0x3f3f3f3f3f3f3f; const ll MOD=1e9+7; int par[2][MAX],cnt[MAX][MAX],sum[MAX][MAX],p1,p2,sum2[MAX][MAX],n,m; vector<int> conn[2][MAX]; void calc(int x1,int x2,int r){ r+=cnt[x1][x2]; sum[x1][x2]=r; for(int i=0;i<conn[1][x2].size();i++) calc(x1,conn[1][x2][i],r); return; } void calc2(int x1,int x2,int r){ r+=sum[x1][x2]; sum2[x1][x2]=r; for(int i=0;i<conn[0][x1].size();i++) calc2(conn[0][x1][i],x2,r); return; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d%d",&par[0][i],&par[1][i]); conn[0][par[0][i]].push_back(i),conn[1][par[1][i]].push_back(i); if(par[0][i]==0) p1=i; if(par[1][i]==0) p2=i; } for(int i=0;i<m;i++){ int t1,t2; scanf("%d%d",&t1,&t2); cnt[t1][t2]++; } for(int i=1;i<=n;i++) calc(i,p2,0); for(int i=1;i<=n;i++) calc2(p1,i,0); for(int i=1;i<=n;i++){ printf("%d\n",sum2[i][i]); } }

Compilation message (stderr)

spy.cpp: In function 'void calc(int, int, int)':
spy.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<conn[1][x2].size();i++) calc(x1,conn[1][x2][i],r);
                 ~^~~~~~~~~~~~~~~~~~~
spy.cpp: In function 'void calc2(int, int, int)':
spy.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<conn[0][x1].size();i++) calc2(conn[0][x1][i],x2,r);
                 ~^~~~~~~~~~~~~~~~~~~
spy.cpp: In function 'int main()':
spy.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
spy.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&par[0][i],&par[1][i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spy.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&t1,&t2);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...