Submission #70487610


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T,N,M;
int X[202020],Y[202020];
int P[202020];
int R[202020];

vector<int> E[202020];
int dp[202020];
int mi=1<<20;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		cin>>N>>M;
		FOR(i,M) {
			cin>>X[i]>>Y[i];
		}
		FOR(i,N) E[i].clear();
		FOR(i,N) {
			cin>>P[i];
			P[i]--;
		}
		FOR(i,M) {
			X[i]=P[X[i]-1];
			Y[i]=P[Y[i]-1];
			E[Y[i]].push_back(X[i]);
		}
		int ma=1;
		dp[0]=1;
		for(i=1;i<N;i++) {
			dp[i]=dp[i-1];
			FORR(e,E[i]) dp[i]=max(dp[i],dp[e]+1);
		}
		
		
		cout<<N-dp[N-1]<<endl;
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task A - Communicate Topological Order
User kmjp
Language C++ 20 (gcc 12.2)
Score 700
Code Size 1400 Byte
Status AC
Exec Time 46 ms
Memory 14984 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:43:21: warning: unused variable ‘ma’ [-Wunused-variable]
   43 |                 int ma=1;
      |                     ^~
Main.cpp:25:15: warning: unused variable ‘j’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |               ^
Main.cpp:25:17: warning: unused variable ‘k’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |                 ^
Main.cpp:25:19: warning: unused variable ‘l’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |                   ^
Main.cpp:25:21: warning: unused variable ‘r’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |                     ^
Main.cpp:25:23: warning: unused variable ‘x’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |                       ^
Main.cpp:25:25: warning: unused variable ‘y’ [-Wunused-variable]
   25 |         int i,j,k,l,r,x,y; string s;
      |                         ^
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:6:19: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:60:9: note: in expansion of macro ‘FOR’
   60 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |         ^~~
Main.cpp:6:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:60:45: note: in expansion of macro ‘FOR’
   60 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~
Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
Main.cpp:60:45: note: in expansion of macro ‘FOR’
   60 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 70
Set Name Test Cases
Sample sample.txt
All dense_1.txt, dense_10.txt, dense_2.txt, dense_3.txt, dense_4.txt, dense_5.txt, dense_6.txt, dense_7.txt, dense_8.txt, dense_9.txt, line_1.txt, line_10.txt, line_2.txt, line_3.txt, line_4.txt, line_5.txt, line_6.txt, line_7.txt, line_8.txt, line_9.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_2.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_3.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_4.txt, random_40.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
dense_1.txt AC 25 ms 8496 KiB
dense_10.txt AC 25 ms 7388 KiB
dense_2.txt AC 27 ms 9752 KiB
dense_3.txt AC 26 ms 7940 KiB
dense_4.txt AC 25 ms 7428 KiB
dense_5.txt AC 27 ms 8212 KiB
dense_6.txt AC 26 ms 8412 KiB
dense_7.txt AC 28 ms 11132 KiB
dense_8.txt AC 27 ms 9128 KiB
dense_9.txt AC 26 ms 8328 KiB
line_1.txt AC 33 ms 7876 KiB
line_10.txt AC 37 ms 11104 KiB
line_2.txt AC 37 ms 11356 KiB
line_3.txt AC 32 ms 9916 KiB
line_4.txt AC 31 ms 10364 KiB
line_5.txt AC 32 ms 7212 KiB
line_6.txt AC 34 ms 8488 KiB
line_7.txt AC 38 ms 14940 KiB
line_8.txt AC 34 ms 9768 KiB
line_9.txt AC 35 ms 8636 KiB
random_1.txt AC 46 ms 14880 KiB
random_10.txt AC 23 ms 11560 KiB
random_11.txt AC 36 ms 10220 KiB
random_12.txt AC 46 ms 14888 KiB
random_13.txt AC 38 ms 11216 KiB
random_14.txt AC 34 ms 11648 KiB
random_15.txt AC 45 ms 14804 KiB
random_16.txt AC 36 ms 9896 KiB
random_17.txt AC 33 ms 10032 KiB
random_18.txt AC 35 ms 13668 KiB
random_19.txt AC 31 ms 10072 KiB
random_2.txt AC 46 ms 14924 KiB
random_20.txt AC 44 ms 14792 KiB
random_21.txt AC 44 ms 14736 KiB
random_22.txt AC 45 ms 14876 KiB
random_23.txt AC 43 ms 13212 KiB
random_24.txt AC 40 ms 14220 KiB
random_25.txt AC 45 ms 13876 KiB
random_26.txt AC 23 ms 10248 KiB
random_27.txt AC 37 ms 10660 KiB
random_28.txt AC 46 ms 14880 KiB
random_29.txt AC 45 ms 14824 KiB
random_3.txt AC 25 ms 12108 KiB
random_30.txt AC 34 ms 9740 KiB
random_31.txt AC 37 ms 10896 KiB
random_32.txt AC 39 ms 11140 KiB
random_33.txt AC 29 ms 9792 KiB
random_34.txt AC 46 ms 14844 KiB
random_35.txt AC 36 ms 8412 KiB
random_36.txt AC 38 ms 10156 KiB
random_37.txt AC 46 ms 14916 KiB
random_38.txt AC 27 ms 12368 KiB
random_39.txt AC 36 ms 8500 KiB
random_4.txt AC 39 ms 12728 KiB
random_40.txt AC 22 ms 11512 KiB
random_5.txt AC 37 ms 10412 KiB
random_6.txt AC 46 ms 14984 KiB
random_7.txt AC 45 ms 14876 KiB
random_8.txt AC 36 ms 9852 KiB
random_9.txt AC 39 ms 11356 KiB
sample.txt AC 2 ms 3444 KiB
small_1.txt AC 26 ms 3452 KiB
small_2.txt AC 27 ms 3528 KiB
small_3.txt AC 26 ms 3392 KiB
small_4.txt AC 26 ms 3528 KiB
small_5.txt AC 26 ms 3652 KiB
small_6.txt AC 26 ms 3464 KiB
small_7.txt AC 27 ms 3464 KiB
small_8.txt AC 26 ms 3584 KiB
small_9.txt AC 11 ms 3652 KiB