QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756701 | #3570. Guards | gyydp123_LIM | 0 | 46ms | 13448kb | C++14 | 2.0kb | 2024-11-16 21:36:32 | 2024-11-16 21:36:37 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=1e5+5,inf=1e6;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
char ch=getchar();int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')
x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
pair<int,int>Tofa[N];int tot;
vector<int>Point[N];
vector<pair<int,int> >Edge[N];
vector<int>G[N];
bool input(){
int n,m,w;
if(scanf("%d%d%d",&n,&m,&w)!=3) return 0;int id=++tot;
For(i,1,m){
int u=read(),v=read();
Edge[tot].emplace_back(u,v);
Point[tot].emplace_back(u);
Point[tot].emplace_back(v);
}sort(Point[tot].begin(),Point[tot].end());
Point[tot].erase(unique(Point[tot].begin(),Point[tot].end()),Point[tot].end());
For(i,1,w){
int u=read(),v=read();
G[id].emplace_back(tot+1);
Tofa[tot+1]={u,v};input();
}return 1;
}
ll f[N][2];bool ok[1<<11],vis[N];
void dfs(int u){
f[u][0]=f[u][1]=inf;
for(int v within G[u]) dfs(v);
int n=Point[u].size(),m=Edge[u].size();
For(S,0,(1<<n)-1){
ok[S]=1;For(j,0,n-1) vis[Point[u][j]]=(S>>j)&1;
For(j,0,m-1) if(!vis[Edge[u][j].first]&&!vis[Edge[u][j].second]){ok[S]=0;break;}
if(!ok[S]) continue;
ll cnt=__builtin_popcount(S);
for(int v within G[u])
if(vis[Tofa[v].first]) cnt+=f[v][1];
else cnt+=min(f[v][0],f[v][1]);
// debug("%d %d %d\n",u,S,cnt);
if(vis[Tofa[u].second]) f[u][1]=min(f[u][1],cnt);
else f[u][0]=min(f[u][0],cnt);
}// debug("%d %d\n",f[u][0],f[u][1]);
}
void ljy(){
dfs(1);printf("%d\n",min(f[1][0],f[1][1]));
For(i,1,tot) G[i].clear(),Point[i].clear(),Edge[i].clear();tot=0;}
signed LJY(){while(input()) ljy();}
详细
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 46ms
memory: 13448kb
input:
5 8 2 1 2 2 4 3 4 1 3 1 5 2 5 3 5 4 5 1 6 3 3 0 6 7 7 8 8 6 5 10 3 2 2 10 11 10 12 11 13 2 1 0 13 9 11 14 3 2 0 14 15 14 16 5 8 2 1 2 2 4 3 4 1 3 1 5 2 5 3 5 4 5 2 7 3 3 0 7 9 7 8 8 9 3 11 3 2 0 11 12 11 13 5 4 2 2 1 3 2 4 1 5 4 4 8 5 4 0 7 6 8 6 9 6 10 9 5 15 5 4 0 12 11 13 11 14 12 15 12 5 4 2 2 1...
output:
8 6 7 7 7 8 7 9 10 10 11 8 8 9 8 11 12 12 13 15 13 10 12 12 13 13 15 15 18 13 12 15 16 17 17 20 18 20 8 8 9 9 10 10 10 13 13 11 11 12 14 13 15 15 16 16 13 14 15 15 15 19 19 20 21 13 15 17 16 23 22 23 24 26 9 12 11 12 10 13 12 14 15 11 12 14 15 16 17 19 19 21 15 16 20 19 20 21 23 25 24 19 21 21 20 24...
result:
wrong answer 13th lines differ - expected: '10', found: '8'